您的位置:首页 > Web前端 > BootStrap

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>

另外,关于时间格式的更改,以下为官方文档翻译(自己翻译的)


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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: