Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Mongodb Timestamp Timezone Misleading

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?

like image 886
fatiherdem Avatar asked Oct 28 '25 21:10

fatiherdem


1 Answers

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.

like image 200
Alex Avatar answered Oct 30 '25 12:10

Alex