Spring Mongodb Timestamp时区误导 [英] Spring Mongodb Timestamp Timezone Misleading

查看:384
本文介绍了Spring Mongodb Timestamp时区误导的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring Data MongoDB.当我保存一些记录时,MongoDb无法正确保存我的时间戳.

I am using Spring Data MongoDB. When I save some records MongoDb doesn't save correctly my timestamp.

这是我在Spring的时间戳字段.

Here is my timestamp field in Spring.

@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private Date timestamp = new Date();

我的MongoDB记录.

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

我该如何更正MongoDB时间戳记?

How can I correct time MongoDB timestamp?

推荐答案

默认情况下,MongoDB将时间存储在UTC中,并将任何本地时间表示形式转换为这种形式,请参见

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.

这篇关于Spring Mongodb Timestamp时区误导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆