获取bootstrap-datetimepicker的值

57 篇文章 0 订阅
53 篇文章 0 订阅
<div class="form-group">
              <label for="startTime">开始时间</label>
              <div class='input-group date' id='startTime'>
                <input type='text' class="form-control" readonly="readonly" />
                <span class="input-group-addon">
                  <span class="glyphicon glyphicon-calendar"></span>
                </span>
              </div>

            </div>
            <div class="form-group">
              <label for="endTime">结束时间</label>              
              <div class='input-group date' id='endTime'>
                <input type='text' class="form-control" readonly="readonly" />
                <span class="input-group-addon">
                  <span class="glyphicon glyphicon-calendar"></span>
                </span>
              </div>
            </div>

方法1:

$("#startTime").data("datetimepicker").getDate()

以上得到的值:
Fri Jun 21 2019 14:10:11 GMT+0800 (中国标准时间)

但是我在与后台传输时要变成时间戳,所以需要转化下:
Math.round(new Date() / 1000) 获取秒数的时间戳
此时只需要把上面的值传入到这个方法就行

let start =$("#startTime").data("datetimepicker").getDate()
let res = Math.round(new Date(start)/1000);

就可以得到秒的时间戳了。

方法2:

$("#startTime").find("input").val();

也可以获取时间控件的值

如果想格式化日期时间: yyyy-MM-dd hh:mm:ss

  var date = new Date('Thu May 12 2017 08:00:00 GMT+0800 (中国标准时间)');  
date_value=date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();  
console.log('这是格式化好的data值'+date_value)

参考:https://blog.csdn.net/m0_37355951/article/details/78052731
https://blog.csdn.net/sun124608666/article/details/74331818

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值