问题描述
使用PHP time()
和使用new MongoDate()
有区别吗?我需要按mongoDB集合存储每个文档的created_at和updated_at日期这样我就可以按日期查询它们(例如,上周更新的文档).
Is there a difference between using PHPs time()
and using new MongoDate()
?I need to store created_at and updated_at dates for each documents in by mongoDB collectionso that I can query them by date (for example documents updated last week).
从我看到的time()和新的MongoDate()产生相同的结果?
From what I can see time() and new MongoDate() produces the same result?
推荐答案
这是因为MongoDate
构造函数的默认设置为time()
,
That's because time()
is default for the MongoDate
constructor, from the manual:
public MongoDate::__construct ([ int $sec = time() [, int $usec = 0 ]] )
您应该使用MongoDate
对象来查询MongoDB.
You should use MongoDate
objects to query MongoDB.
如果使用time()
的原始输出,则将存储/查询整数.使用MongoDate
时,将使用MongoDB的日期类型,它会为您提供一些额外的信息好处.
If you use the raw output of time()
, you will store/query for an integer. When you use MongoDate
, you will be using MongoDB's Date type which gives you some additional benefits.
这篇关于time()和新的MongoDate()之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!