logbon72 / angular-material-datetimepicker

Datepicker for Angular Material, mimick's Android's date time picker
https://logbon72.github.io/angular-material-datetimepicker
MIT License
169 stars 123 forks source link

Display in Local Timezone #123

Open art1c0 opened 6 years ago

art1c0 commented 6 years ago

Module seems to save dates in local time, but displays in UTC, which I believe incorrect and causes issue when date changes after saving if your browser and server are in different time zones.

hexadecy commented 6 years ago

By default, moment parses and displays in local time. // 2017-10-19T10:35:24-08:00 But your server and javascript object should/must be in UTC. Your can use getTimezoneOffset() to pass the value to the server when you can't use the web browser to display the datetime.

art1c0 commented 6 years ago

I provide an example: Imagine I set datetimepicker to 20th of October 14:00 (I am in the GMT+2 timezone). When this date is being converted to JSON it becomes UTC: "2017-10-20T12:00:00.549Z" - this is correct value which is sent to the server. It is still the same moment in time. Then in reading mode the same exact value is coming from the server "2017-10-20T12:00:00.549Z" - and the browser is still in the same timezone of GMT+2, but now the picker displays 12:00 insted of 14:00. It seems it just reads the date ignoring the timezone. Got my point?

hexadecy commented 6 years ago

Which javascript REST lib are you using? moment.js 2.18.1 and other deps version? I'm using angular-resource 1.6.6 that auto transform with angular.fromJson and I don't have the issue you described.

hexadecy commented 6 years ago

You can now force the timezone by adding this in the html: ng-model-options="{timezone: 'utc'}" or ng-model-options="{timezone: '+0200'}" https://github.com/beenote/angular-material-datetimepicker/releases/tag/v1.13.0