angular-material-datetimepicker icon indicating copy to clipboard operation
angular-material-datetimepicker copied to clipboard

Display in Local Timezone

Open art1c0 opened this issue 6 years ago • 4 comments

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.

art1c0 avatar Oct 18 '17 19:10 art1c0

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.

hexadecy avatar Oct 20 '17 02:10 hexadecy

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?

art1c0 avatar Oct 20 '17 09:10 art1c0

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 avatar Oct 20 '17 13:10 hexadecy

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

hexadecy avatar Feb 10 '18 04:02 hexadecy