Reputation: 23
The calendar should be showing Oct 19, 2016, but it keeps showing Oct 18, 2016. I can't figure out why!
$('#datepickerDateReceived').datepicker({
format: 'yyyy-mm-dd'
}).datepicker(
'setDate', new Date('2016-10-19')
);
Upvotes: 2
Views: 3860
Reputation: 143
This does not work in Safari: $('#datepickerDateReceived').datepicker('setDate', new Date('2016-10-19 00:00'));
I had to put it this way to make it work in Safari: $('#datepickerDateReceived').datepicker('setDate', new Date('2016-10-19 00:00'.replace(/\s/, 'T')));
Upvotes: 2
Reputation: 673
The problem is that date strings are parsed as UTC 0, not local time-zone. source
To fix it, just add a time to your date string
$('#datepickerDateReceived').datepicker({
format: 'yyyy-mm-dd'
}).datepicker(
// Initialize the date to be 00:00 local timezone on October 19, 2016
'setDate', new Date('2016-10-19 00:00')
);
Upvotes: 0