revskill
revskill

Reputation: 31

Mongoid DateTime: What is the right date?

I'm using Mongoid to store DateTime. But now i'm confusing with the real date. In mongodb , the date is stored as:

{"2013-01-14T12:50:00.000Z"} 

But when i print that value, it says:

2013-01-14T19:50:00+07:00

I don't really understand whether those Date formats are the same, and which one is "right" in my current timezone ?

Thank you for your help.

Upvotes: 0

Views: 1212

Answers (2)

Sammaye
Sammaye

Reputation: 43884

The default Ruby date object should be able to handle offsets in time:

http://ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html

Whereby some way down the page it even talks about how to start manipulating it I believe:

An optional argument the offset indicates the difference between the local time and UTC.

I do believe that mongoid is already converting the time for you as can be seen by the T value within the iso date being 7 hours ahead:

2013-01-14T19:50:00+07:00

Merely if you were to print the date and/or time instead of the full output with the offset included I have no doubt you will get the real date.

I believe mongoid most likely prints the offset even when it is applied because that offset IS there (since the time is off-setted by 7 hours from UTC) it is just not applied further.

Upvotes: 1

Olegas
Olegas

Reputation: 10507

Date is stored in GMT, when "printed", it is displayed in your local timezone (GMT+7?)

Upvotes: 2

Related Questions