Can't get date object from Bootstrap DateTimePicker via JQuery

假如想象 提交于 2020-02-24 03:57:46

问题


I can't get the date object after selecting the datetime from the datetimepicker box. How can I get the datetime object and transform it into unix integer?

Here's my html code:

<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>

Here's my css:

<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/css/bootstrap-datetimepicker.css" rel="stylesheet"/>

And here 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));

回答1:


You can access the date value like this:

var date = $('#startDate').data('DateTimePicker').date();

The date time picker documentation states:

Note All functions are accessed via the data attribute e.g. $('#datetimepicker').data("DateTimePicker").FUNCTION()



来源:https://stackoverflow.com/questions/38148966/cant-get-date-object-from-bootstrap-datetimepicker-via-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!