bootstrap datetimepicker 插件怎样获取时间值
2016-09-19 17:05
721 查看
今天一个简单的问题搞了比较久,就是datetimepicker这个插件怎样获取时间并且将时间的格式改变的问题,答案如下:
开始时间:
<div class="controls input-append date form_datetime " data-date-format="yyyy-mm-dd hh:ii " data-link-field="dtp_input1"> <input id="start_time" class="form-control input-sm" size="20" type="text" value=""
readonly>
<span class="add-on"><i class="icon-remove"></i></span><span class="add-on"><i class="icon-th"></i></span>
<div>
<script type="text/javascript"> </div>
//时间选择器
$(".form_datetime").datetimepicker({
language: "zh-CN",
weekStart: 1,
todayBtn: 1,
autoclose: 1,
todayHighlight: 1,
startView: 2,
forceParse: 0,
showMeridian: 1
});
//jquery选择器获取时间值,.val()方法
$("#data").click(function(){
console.log($("#datetime").val());
});
<script>
另外,关于时间格式的更改,以下为官方文档翻译(自己翻译的)
String. 默认值: 'mm/dd/yyyy'
日期格式, p, P, h, hh, i, ii, s, ss, d, dd, m, mm, M, MM, yy, yyyy 的任意组合。
p : meridian in lower case ('am' or 'pm') - according to locale file 根据本地文件:p 小写(pm am)中文的话就没区别
P : meridian in upper case ('AM' or 'PM') - according to locale file 根据本地文件:P 大写(pm am)中文的话就没区别
s : seconds without leading zeros 没有0开头的秒(ex:14:05:5 14时05分5秒)
ss : seconds, 2 digits with leading zeros 有0开头的秒(ex:14:05:05 14时05分05秒)
i : minutes without leading zeros 没有0开头的分(ex:14:05:5 14时05分05秒)
ii : minutes, 2 digits with leading zeros
有0开头的分(ex:14:05:05 14时05分05秒)
h : hour without leading zeros - 24-hour format没有0开头的时,24小时格式(ex:4:05:5
4时05分05秒)
hh : hour, 2 digits with leading zeros - 24-hour format有0开头的时,24小时格式(ex:04:05:05
04时05分05秒)
H : hour without leading zeros - 12-hour format没0开头的时,12小时格式(ex:04:05:05 04时05分05秒)
HH : hour, 2 digits with leading zeros - 12-hour format有0开头的时,14小时格式(ex:04:05:05
04时05分05秒)
d : day of the month without leading zeros
同上,这里不再一一叙述
dd : day of the month, 2 digits with leading zeros
m : numeric representation of month without leading zeros月份
数字月份,建议使用 不带0
mm : numeric representation of the month, 2 digits with leading zeros 月份 数字月份,建议使用
M : short textual representation of a month, three letters 月份 缩写 主要是对于英语月份
MM : full textual representation of a month, such as January or March 月份 全拼 主要是对于英语月份 ex: January
、 March
yy : two digit representation of a year
年份后两位,如2016年写为16
一般情况下日期的格式应该和数据库的格式匹配,这样的话就不用进行转换,提高开发效率。推荐格式 yyyy-mm-dd hh-ii
开始时间:
<div class="controls input-append date form_datetime " data-date-format="yyyy-mm-dd hh:ii " data-link-field="dtp_input1"> <input id="start_time" class="form-control input-sm" size="20" type="text" value=""
readonly>
<span class="add-on"><i class="icon-remove"></i></span><span class="add-on"><i class="icon-th"></i></span>
<div>
<script type="text/javascript"> </div>
//时间选择器
$(".form_datetime").datetimepicker({
language: "zh-CN",
weekStart: 1,
todayBtn: 1,
autoclose: 1,
todayHighlight: 1,
startView: 2,
forceParse: 0,
showMeridian: 1
});
//jquery选择器获取时间值,.val()方法
$("#data").click(function(){
console.log($("#datetime").val());
});
<script>
另外,关于时间格式的更改,以下为官方文档翻译(自己翻译的)
format
String. 默认值: 'mm/dd/yyyy'日期格式, p, P, h, hh, i, ii, s, ss, d, dd, m, mm, M, MM, yy, yyyy 的任意组合。
p : meridian in lower case ('am' or 'pm') - according to locale file 根据本地文件:p 小写(pm am)中文的话就没区别
P : meridian in upper case ('AM' or 'PM') - according to locale file 根据本地文件:P 大写(pm am)中文的话就没区别
s : seconds without leading zeros 没有0开头的秒(ex:14:05:5 14时05分5秒)
ss : seconds, 2 digits with leading zeros 有0开头的秒(ex:14:05:05 14时05分05秒)
i : minutes without leading zeros 没有0开头的分(ex:14:05:5 14时05分05秒)
ii : minutes, 2 digits with leading zeros
有0开头的分(ex:14:05:05 14时05分05秒)
h : hour without leading zeros - 24-hour format没有0开头的时,24小时格式(ex:4:05:5
4时05分05秒)
hh : hour, 2 digits with leading zeros - 24-hour format有0开头的时,24小时格式(ex:04:05:05
04时05分05秒)
H : hour without leading zeros - 12-hour format没0开头的时,12小时格式(ex:04:05:05 04时05分05秒)
HH : hour, 2 digits with leading zeros - 12-hour format有0开头的时,14小时格式(ex:04:05:05
04时05分05秒)
d : day of the month without leading zeros
同上,这里不再一一叙述
dd : day of the month, 2 digits with leading zeros
m : numeric representation of month without leading zeros月份
数字月份,建议使用 不带0
mm : numeric representation of the month, 2 digits with leading zeros 月份 数字月份,建议使用
M : short textual representation of a month, three letters 月份 缩写 主要是对于英语月份
MM : full textual representation of a month, such as January or March 月份 全拼 主要是对于英语月份 ex: January
、 March
yy : two digit representation of a year
年份后两位,如2016年写为16
一般情况下日期的格式应该和数据库的格式匹配,这样的话就不用进行转换,提高开发效率。推荐格式 yyyy-mm-dd hh-ii
相关文章推荐
- bootstrap-datetimepicker 获取时间
- angularjs封装bootstrap时间插件datetimepicker
- bootstrap 时间插件bootstrap-datetimepicker设置语言
- bootstrap中datetimepicker时间插件使用
- 时间插件-bootstrap-datetimepicker2.3.11
- bootstrap datetimepicker日期时间插件的使用
- bootstrap datetimepicker2.3.11时间插件使用
- datetimepicker bootstrap的时间插件显示位置问题及其他配置
- bootstrap-datetimepicker 时间日期插件
- bootstrap-datetimepicker.js 设置开始时间的Bug。
- Bootstrap时间选择器datetimepicker和daterangepicker使用实例解析
- BootStrap中Datetimepicker和uploadify插件应用实例小结
- 关于bootstrap-datetimepicker 插件的配置参数详解
- bootstrap-datetimepicker 时间控件位置问题
- DateTimePicker:jQuery日期和时间插件
- Bootstrap时间选择器datetimepicker和daterangepicker使用实例解析
- DateTimePicker:jQuery日期和时间插件
- Bootstrap时间控件 datetimepicker
- bootstrap日期插件datetimepicker的简单使用
- BootStrap-datetimepicker插件有滚动条时出现位移问题解决方案