<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