Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB java-driver insert date

I'm using MongoDB 2.2 with java-driver 2.10.1

I'm inserting a date field into a document from a java.util.Date instance. My instance has the following value:

Wed Oct 10 00:00:00 CEST 2012

but once in mongo, I have this value: ISODate("2012-10-09T22:00:00Z")

My insertion code:

BasicDBObject doc =  new BasicDBObject("key", event.getKey())
                    .append("title", event.getTitle())
                    .append("description",  event.getDescription())
                    .append("date",  event.getDate());
db.getCollection("events").insert(doc);

You can have a look to the date instance referenced from my event object on this debug screenshot: enter image description here

Is there something to do with the timezone ? Or a bug from the driver ?

like image 607
krampstudio Avatar asked Jan 29 '13 12:01

krampstudio


1 Answers

Dates in MongoDB are always stored as UTC datetimes, so what you're seeing is correct.

The CEST time zone is two hours ahead of UTC (GMT) so your time's correct UTC representation is two hours earlier than your CEST time, which is exactly what you're seeing.

like image 68
JohnnyHK Avatar answered Sep 22 '22 00:09

JohnnyHK