Timezone problem?
Closed this issue · 5 comments
Can i store a date directly with my current timezone?
When i select a date, the model is always 2 hours sooner than the selected date.
Example: https://jsfiddle.net/SebSob/su0uxLyw/3/
How to reproduce?
- Select 25 May in the picker.
- You will then see that the date object stores it as:
"data": {
"dueDate": "2018-05-24T22:00:00.000Z"
}
- What i expect: 2018-05-25T00:00:00.000Z
Note: When i use angularJS's date filter it displays it correctly.
I live in Belgium. When i run new Date():
Wed May 23 2018 16:59:47 GMT+0200 (Romance Daylight Time)
Can someone please explain this, I'm confused, thanks!
I'm facing the same issue. Tried changing the moment default timezone by following the instruction mentioned in the moment-timezone documentation, but this doesn't fix it.
If you're able to work with a string, I think I found a (hacky?) way to solve it; by adding the following modelType property to datetimepicker-config:
modelType: 'YYYY-MM-DDT00:00:00.000[Z]'
Example: https://jsfiddle.net/gx05t5gw/1/
But I'm not completely sure about the consequences.
//edit:
Apparently no disastrous consequences, except the obvious:
strings are problematic and often lose timezone information, so use caution when storing strings
https://github.com/dalelotts/angularjs-bootstrap-datetimepicker#modeltype
Yeah, this stuff can be confusing. There is a native JavaScript Date stored in the model, but you display it on the screen or serialize the DATe to JSON it is no longer a a native JavaScript Date , it is now (usually) a string.
The string representation may not display or look as you expect (JSON serialization of Date's it not the same as the toString of the date. ) - that does not necessarily mean the date stored in the model is incorrect. It is beyond the scope of this project to include detailed information about JavaScript dates, the various ways to represent those dates, or the problems with native JS Dates.
IMO, you can trust that the JS Date object stored in the model is correct (it really is well tested - look through the issues and you will see that most are not bugs).
For example, new Date( "2018-05-24T05:00:00.000Z") prints Thu May 24 2018 00:00:00 GMT-0500 (CDT) in my browser - try the same thing in your browser and you will see different output.
@dalelotts Ok, thanks for the explanation! It's clear now.
So, is this a good way to go?:
I've set the modelType to 'moment'. This will store the date (eg. 15th June) like this:
"2018-06-14T22:00:00.000Z"
Later when I need the date I just pass it to moment() like so:
moment("2018-06-14T22:00:00.000Z").format()
which will output: "2018-06-15T00:00:00+02:00" (which is indeed the same as the selected date)
Hi, can you guys help me to format dates in pgadmin? If I've saving the times in the database, and there is something like Start - 2017-09-15T22:00:00.000Z, End - 2017-10-21T22:00:00.000Z Is there any way to remove this part of the data? 'T22:00:00.000Z'
I would like to save just only Start - 2017-09-15, End - 2017-10-21 😕