Mongodb 纪元日期 - java 映射

Mongodb Epoch Date - java mapping

我想以纪元格式(以秒或毫秒为单位的 Unix 时间,例如:“1433323417000”)在 mongodb 中存储日期,并在 java java.util.Date 中有一个对象映射格式(或 joda.time.DateTime)。 你能告诉我这是否可行吗?

提前致谢

来自 MongoDb 文档:

Internally, Date objects are stored as a 64 bit integer representing the number of milliseconds since the Unix epoch (Jan 1, 1970), which results in a representable date range of about 290 millions years into the past and future. https://docs.mongodb.org/manual/reference/method/Date/

您可以找到一些有关如何使用 Java 驱动程序插入的示例 here

阅读时,没有什么能阻止您将日期转换为您想要的任何格式。