从日期时间选择器框中选择日期时间后,我无法获得日期对象。我如何获得datetime对象并将其转换为unix整数?
下面是我的html代码:
<div class="form-group" align="center">
<div class='input-group date' id="startDate">
<input type='text' class="form-control" name="org_startDate" placeholder="Wo" data-format="yyyy-MM-dd hh:mm:ss"/>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
这是我的css:
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
这里是my js:
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script>
jQuery(function () {
jQuery('#startDate').datetimepicker({
locale: 'de',
format: 'dd, DD.MM.YYYY, HH:mm',
minDate: moment(),
});
});
// WHAT CODE DO I NEED HERE TO GET DATE OBJECT AND TRANSFORM IT INTO UNIX INTEGER
var dateStr = $("#startDate").find("input").val();
var date = Date.parse(dateStr);
alert(date + " " + new Date(date));
您可以这样访问日期值:
var date = $('#startDate').data('DateTimePicker').date();
日期时间选择器文档说明:
注意所有的函数都是通过data属性来访问的。$ (' # datetimepicker ') . data (datetimepicker) .FUNCTION ()