2

I have an angular 1.5 application where i make use of a moment datepicker library from here : angular moment date picker Everything has worked well until recently when we realized that the date pickers rendered dates wrongly across different user pc's .It appears this may have something to do with how JavaScript handles time zones: In the image below October 1, 2017 is actually a Sunday but the date picker renders it as a Monday albeit I get the correct values rendered on my own pc running a more current version of google chrome perhaps this is also a browser issue ?

IE does show dates as I would expect. see the html snippet for the input below:

 <input class="form-control input-sm"
                                                           ng-model="vm.form.StartDateTime"
                                                           format="DD-MMM-YYYY, HH:mm:ss"
                                                           ng-model-options="{ updateOn: 'blur' }"
                                                           start-view="month"
                                                           moment-picker="vm.form.StartDateTime" />

JS: moment(self.form.StartDateTime)

date picker image

The primary question is how can I ensure date-times are represented correctly across different time zones on the date picker ?

lacoder
  • 1,253
  • 1
  • 11
  • 22
  • I had a similar issue several weeks ago. JS will take the time in GMT and the 'localize' it based off your host system. So if I wanted to find the most recent date in an arr of JSON objects it would not return "2017-05-08" (GMT) even if that was the most recent date. Rather it would send "2017-05-07" (CST) because of the time zone difference. I used the getTimezoneOffset() method of the JS API to correct it. See this for more details: https://stackoverflow.com/questions/7556591/javascript-date-object-always-one-day-off – jrDeveloper Sep 29 '17 at 03:41
  • Ooo. This looks helpful as well. Didn't even pay attention to the moment.js lib: https://momentjs.com/timezone/docs/ – jrDeveloper Sep 29 '17 at 19:21
  • I have tried a couple of things yet the issue still occurs. Dates are ok on one pc but different on another pc even in the same timezone! Perhaps I would need to edit the moment-picker.js library ?I used `getTimezoneOffset()` to no avail – lacoder Sep 30 '17 at 00:27

0 Answers0