有没有办法存储日期时间?这样我就可以计算两个日期时间之间的时间差并查询日期时间范围。
另外我想指出一个确切的时间。例如)2001 年 1 月 1 日 12:00:00
我应该用时区或其他更好的方法来存储 unix 时间戳时间和日期时间字符串来处理这个问题吗?
最佳答案
你应该使用 MongoDate用于在 MongoDB 中存储日期的类。
从手册...
MongoDB stores dates as milliseconds past the epoch. This means that dates do not contain timezone information. Timezones must be stored in a separate field if needed
您可以通过检索 sec
属性并在 DateTime::setTimestamp()
中使用它来将这些转换为 DateTime
对象.另见 DateTime::setTimezone()
关于php - 如何使用 php 处理 mongoDB 中的 "datetime"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7021678/