简体   繁体   English

在MongoDB中的不同字段中设置日期和时间

[英]Set Date and Time in Different Field in MongoDB

I am inserting Date Object from Java to Mongodb, mongo ISODate(...) stores Date with Time, my requirement is to Store both in different field. 我将日期对象从Java插入Mongodb,mongo ISODate(...)存储Date with Time,我的要求是将两者存储在不同的字段中。

is this possible ? 这可能吗 ?

note : don't want solution that stores milliseconds instead of date. 注意 :不希望存储毫秒而不是日期的解决方案。 want to store only date like "2013-06-19" and time like "00:00:00" 想只保存“2013-06-19”之类的日期和“00:00:00”之类的时间

if i use String format for this than hard to perform date operation. 如果我使用String格式而不是难以执行日期操作。

您可以将Date对象转换为unix时间戳作为timestamp ,然后将timestamp / 86400存储到字段,将timestamp % 86400到另一个字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM