You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I originally rewrote the date logic to UTC, so I would like to elaborate on why I think this is the correct behavour. Mind you I haven't looked at the code lately, so im just speaking from memory :).
The two dates you posted represent the same point in time:
d1=newDate('2013-11-02 00:00:00Z')SatNov02201301:00:00GMT+0100(W.EuropeStandardTime)d2=newDate('Sat Nov 01 2013 22:00:00 GMT-0200 (BRST)')SatNov02201301:00:00GMT+0100(W.EuropeStandardTime)d1.getTime()1383350400000d2.getTime()1383350400000d1.getTime()===d2.getTime()true
Model.date is a javascript Date object, and those are always in the local timezone. If you want to the get the UTC time of a Date, you will have to write custom logic using .getUTCDate() etc. When you pass a date object to sequelize it is converted to UTC before it is saved, not matter what local time zone it has. When you retrieve a date object is created, representing the UTC timestamp in the local timezone of your server. This means that even if you save a date from a server in one timezone and retrieve it from a server in another zone, the date objects will represent the same point in time (their timestamps are equal), even though their .toString() representation will be different.
In short you should not take extra care to convert your dates to UTC before passing them to sequelize, sequelize will handle the conversion.
@janmeier I think the problem exists. d1 = new Date('2013-11-02 00:00:00Z')
You added Z which change the time making it different from the one in mysql.
Activity
janmeier commentedon Nov 4, 2013
I originally rewrote the date logic to UTC, so I would like to elaborate on why I think this is the correct behavour. Mind you I haven't looked at the code lately, so im just speaking from memory :).
The two dates you posted represent the same point in time:
Model.date is a javascript Date object, and those are always in the local timezone. If you want to the get the UTC time of a Date, you will have to write custom logic using
.getUTCDate()etc. When you pass a date object to sequelize it is converted to UTC before it is saved, not matter what local time zone it has. When you retrieve a date object is created, representing the UTC timestamp in the local timezone of your server. This means that even if you save a date from a server in one timezone and retrieve it from a server in another zone, the date objects will represent the same point in time (their timestamps are equal), even though their.toString()representation will be different.In short you should not take extra care to convert your dates to UTC before passing them to sequelize, sequelize will handle the conversion.
jonhkr commentedon Nov 4, 2013
So, I solved my problem by converting the date value to UTC again using a model getter method.
Thanks @janmeier for clarifying it.
janmeier commentedon Nov 5, 2013
You're welcome :)
tomwang1013 commentedon Nov 19, 2014
@janmeier I think the problem exists.
d1 = new Date('2013-11-02 00:00:00Z')You added
Zwhich change the time making it different from the one in mysql.