JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://momentjs.com/downloads/moment.min.js"></script>
<script src="http://momentjs.com/downloads/moment-timezone-with-data.js"></script>
<script src="http://visavie.me/test/js/jquery.datetimepicker.js"></script>
<link rel="stylesheet" href="http://visavie.me/test/css/jquery.datetimepicker.css">
<input id="datetimepicker" type="text" class="textoxdate">
JavaScript
$(document).ready(function () {
var today;
var time = 1443597652;
var newyorktime = time - 5*60*60;
today = new Date(newyorktime*1000);
var dd = today.getDate();
var mm = today.getMonth();
var yy = today.getFullYear();
var hh = today.getHours();
var now = new Date(newyorktime*1000);
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) {
var currentDateTimestamp = moment(currentDateTime).unix()-5*60*60; //substract 5 hours so that we can get the current time in new york
currentDateTime = new Date(currentDateTimestamp*1000); //create a date object again
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'
});
};
$('#datetimepicker').val(dd+"/"+(mm+1)+"/"+yy+" "+time);
jQuery('#datetimepicker').datetimepicker({
onChangeDateTime: logic,
onShow: logic
});
}
);