我正在使用datetimepicker js脚本并实现以下逻辑:
<script>
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth();
var yy = today.getFullYear();
var hh = today.getHours();
var now = new Date();
now.setHours(now.getHours() + 2);
var isPM = now.getHours() >= 12;
var isMidday = now.getHours() == 12;
var result = document.querySelector('#result');
var time = [now.getHours() - (isPM && !isMidday ? 12 : 0),
now.getMinutes()].join(':') +
(isPM ? ' pm' : 'am');
var logic = function (currentDateTime) {
if (currentDateTime.getDate() == dd && currentDateTime.getFullYear() == yy && currentDateTime.getMonth() == mm) {
this.setOptions({
formatTime: 'g:i A',
format: 'd/m/Y h:i A',
minDate: '+1970/01/02', //or 1986/12/08,
minTime: time
});
} else
this.setOptions({
formatTime: 'g:i A',
format: 'd/m/Y h:i A',
minDate: '+1970/01/02', //or 1986/12/08,
minTime: '0:00 AM'
});
};
jQuery('#datetimepicker').datetimepicker({
onChangeDateTime: logic,
onShow: logic
});
</script>
现在我的日期时间选择器看起来像这样 https://i.stack.imgur.com/BemGm.png.
但是当我稍后选择一些日期和时间(使用 var date = $("#datetimepicker").val();
)作为回报时,我有格式30/06/2015 02:04 PM
,但我想有一个时间戳。那么如何将其转换为时间戳呢?
好吧,你可以试试这个:
jQuery('#datetimepicker').datetimepicker("getDate").getTime()/1000
这应该以您想要的时间格式返回它。