Reputation: 1223
I am using Spring Data MongoDB. When I save some records MongoDb doesn't save correctly my timestamp.
Here is my timestamp field in Spring.
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private Date timestamp = new Date();
My MongoDB record.
{
"_id": ObjectId("5697a672ce2a8e5347d86afd"),
"batteryLevel": 100,
"beaconClass": 3,
"beaconId": "dsadsa",
"timestamp": ISODate("2016-01-14T13:45:22.702Z")
}
When I log to console my timezone and date I see it is correct.
Eastern European Time
Asia/Istanbul
Thu Jan 14 15:45:22 EET 2016
How can I correct time MongoDB timestamp?
Upvotes: 4
Views: 16048
Reputation: 1263
I am also using spring data with spring boot. Even if Mongo is storing my current timezone (CEST) in UTC, when I retrieve it with queries from a MongoRepository, it does the conversion automatically and retrieves the desired data.
Upvotes: 2
Reputation: 21766
MongoDB stores times in UTC by default, and will convert any local time representations into this form, see the documentation. You will have to compute the original local time in your application logic.
Upvotes: 10