Date storage timezone question

15 views
Skip to first unread message

Anthony Kinaesthetic

unread,
Oct 17, 2016, 12:54:14 PM10/17/16
to mongodb-user
Hi,

I know Mongodb store a date in UTC (assuming the application sent him the date in UTC), why does it store like that : 2016-10-31 02:00:00.000+02:00 ? 
Isn't it possible to have : 2016-10-31 00:00:00.000+00:00 ?

Where does the +2 come from ? My Linux machine timezone is UTC (but my application is Europe/Paris but even if I change to UTC, it stills store as +2).

Thanks


Lungang Fang

unread,
Oct 23, 2016, 8:43:15 PM10/23/16
to mongodb-user

Hi Anthony,

I know Mongodb store a date in UTC (assuming the application sent him the date in UTC),

Please note that “UTC datetime” and “UTC time” refer to different things. “UTC datetime” basically refers to a data type. This data type is usually a 64-bit integer that represents the number of milliseconds since Unix epoch (‘1970-01-01 00:00:00+0000’). In contrast, “UTC time” means the time in timezone UTC. MongoDB stores dates as numbers of milliseconds since Unix epoch, see BSON type date

why does it store like that : 2016-10-31 02:00:00.000+02:00 ? Isn’t it possible to have : 2016-10-31 00:00:00.000+00:00 ?

It is NOT stored in “2016-10-31 02:00:00.000+02:00”. That string is only one (among many other) presentation of the stored date. A date stored in UTC datetime does not necessarily be presented in UTC time. In fact, most applications present time according to local timezone.

Where does the +2 come from ? My Linux machine timezone is UTC (but my application is Europe/Paris but even if I change to UTC, it stills store as +2).

The “+2” is the offset of your timezone (Paris, Central European Summer Time, CEST). As mentioned earlier, the issue is not how the date is stored but rather how it is presented. Therefore, you may want to check the configuration of the application which reads the date. The following is an example how data output differs with different “TZ” settings.

$ TZ=Australia/Sydney date -R
Thu, 20 Oct 2016 17:11:29 +1100

$ TZ=Asia/Shanghai date -R
Thu, 20 Oct 2016 14:11:36 +0800

$ TZ=US/Eastern date -R
Thu, 20 Oct 2016 02:11:41 -0400

Regards,
Lungang

Reply all
Reply to author
Forward
0 new messages