本文介绍了time()和新的MongoDate()之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用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()之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 22:33