I’m trying to save a Date value from nodejs in my mongodb, but the saved value is one day earlier. More exactly its one hour.
If I use console.log(new Date(this.year, this.month, this.day)); in nodejs I get:
Tue Mar 19 2013 00:00:00 GMT+0100 (CET)
but in mongodb I have following record:
2013-03-18 23:00:00 +0000
the record is one hour earlier.
But why? Have I to set the timezone in mongodb? I'm using Os X with:
Time Zone: Europe/Berlin
MongoDB stores time in UTC only. It is left to the application to do timezone conversions.
It's not one hour earlier — it's stored in mongodb using timezone +00:00 instead of +01:00.
00:00 by +01:00 === 23:00 by +00:00
To avoid the timezone problem, just add process.env.TZ = 'UTC' in the "main".