0

I'm saving some entities to a Mongo database, these have Joda DateTime properties which have UTC set as a timezone. While saving works fine and I see the properties with correct values in the collection, once I retrieve the entities through Java the timezone gets set to UTC+2 again.

This is in the collection:

"created" : ISODate("2013-07-26T20:36:57.890Z")

I'm using Spring-Data-MongoDB to access the database.

Category category = mongoTemplate.findById(id, Category.class);

And I end up with this:

2013-07-26T23:05:56.439+02:00

Is there a way to tell Mongo do return the timezone stored in the date?

Hints appreciated, thank you!

  • 1
    Actually mongo returns what it is in the database, but your program prints it using local settings. I think that is the problem. – innoSPG Jul 26 '13 at 21:27

1 Answers1

1

The driver is returning what the database has as a java.util.Date object. It knows nothing of the timezone that time represents. It does not store the Timezone anywhere. Mongo Shell always presents a time value as UTC.

That being said, if you want to work with it in your application code as UTC always, I think there is a way to tell the JODA library to do this: Defaulting date time zone to UTC for Jodatime's DateTime

Community
  • 1
  • 1
Bob Kuhar
  • 10,838
  • 11
  • 62
  • 115