无法通过 JQuery 从 Bootstrap DateTimePicker 获取日期对象
Can't get date object from Bootstrap DateTimePicker via JQuery
从日期时间选择器框中选择日期时间后,我无法获取日期对象。如何获取日期时间对象并将其转换为 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"/>
这是我的 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();
The date time picker documentation 状态:
Note All functions are accessed via the data attribute e.g.
$('#datetimepicker').data("DateTimePicker").FUNCTION()
从日期时间选择器框中选择日期时间后,我无法获取日期对象。如何获取日期时间对象并将其转换为 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"/>
这是我的 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();
The date time picker documentation 状态:
Note All functions are accessed via the data attribute e.g. $('#datetimepicker').data("DateTimePicker").FUNCTION()