MongoDB, Java: receive date property as UTC

I store some objects in a Mongo database, they have Joda DateTime properties that have UTC as their time zone. Although saving works fine, and I see properties with the correct values ​​in the collection, as soon as I receive objects through Java, the time zone is again set to UTC + 2.

This is in the collection:

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

I am using Spring -Data-MongoDB to access the database.

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

And I get the following:

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

Is there any way to say that Mongo returns the timezone stored in the date?

Tips appreciated, thanks!

0
source share
1 answer

The driver returns what the database has as a java.util.Date object. He knows nothing about the time zone that represents time. It does not store the time zone anywhere. Mongo Shell always represents time as UTC.

If you want to work with it in your application code as always in UTC, I think there is a way to tell the JODA library: The default time for UTC is for the Jodatime DateTime

+1
source

Source: https://habr.com/ru/post/952057/


All Articles