bootstrap datetimepicker 插件怎样获取时间值

今天一个简单的问题搞了比较久,就是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



  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值