Reputation: 1805
I am running mongodb on ubuntu server. The server time is
root# date
Thu Sep 13 21:15:58 BST 2012
But when I run the following command I get a different result
root# mongo
MongoDB shell version: 2.2.0
connecting to: test
> new Date()
ISODate("2012-09-13T20:15:58.670Z")
There is exactly one hour difference. When I update a documents updated_on
field with php using MongoDate()
, the value of the field is still 1 hour off.
[EDIT] Actually I just checked my php error log and the time in the log file is 1 hour off as well
[13-Sep-2012 20:11:14 UTC] Log Message (Time should be 21:11:14)
Upvotes: 5
Views: 9752
Reputation: 1399
To display DateTime on MongoDB is a good idea to use UTC display format (Zulu time). This is a picture to show the menu example to enable this format using NoSQLBooster for MongoDB.
Upvotes: 0
Reputation: 1
On windows change your timezone. Controll Panel -> Date and Time -> Change on timezone -> (UTC) Coordinated universal time. And then just change your time
Upvotes: -3
Reputation: 364
Here you need to understand a concept in time setting in clocks called daylight saving time. In some countries around the world the clock is advanced by 1 or more hours to experience day light by one more hour. The difference between IST and GST is 5.30 hrs but the actual time difference is between New Delhi and London time is 6.30 hrs. See this article from 4GuysFromRolla for setting and using server time.
Upvotes: 0
Reputation: 31
You can resolve this issue by displaying the DateTime with ToLocalTime
method.
MVC C# Example: @Model.StartDate.ToLocalTime()
This is due to the way MongoDB store datetime in BST format. So the daylight savings time or the time zone of the server will have an effect on the actual date time returned to the application. This simple code will be able to format as usual with ToString("dd MMMM yyyy hh:mm tt")
or any other format based on your requirements.
Upvotes: 3
Reputation: 32953
Mongo tells you
2012-09-13T20:15:58.670Z
Z = Zulu time / Zero offset / UTC. You can also express the time in that TZ as 2012-09-13T20:15:58.670+00:00, as defined in the ISO8601 standard by the way.
BST is UTC+1. So, they are the same time but in different time zones.
Upvotes: 6