MongoId
在线手册:中文  英文

MongoId::getTimestamp

(PECL mongo >= 1.0.1)

MongoId::getTimestamp获取新纪元时间到 id 创建时的秒数。

说明

public int MongoId::getTimestamp ( void )

返回 id 创建时运行 time() 同样的东西。

参数

此函数没有参数。

返回值

获取新纪元时间到 id 创建时的秒数。 仅储存了四个字节的时间戳,所以 MongoDate 是储存更精准、更广范围时间的更佳选择。


MongoId
在线手册:中文  英文

用户评论:

alex at nodex dot co dot uk (2013-05-14 09:27:41)

A pretty nifty way to not have to store an "added" key with a record - for example you may need to store when a user joined or w/e - normaly it would be with say "added" : (int)time()
You can save your RAM/Disk space by using getTimestamp(); in the following way
$ts=new MongoId('51547a02bb07f8d96f000723');
$added_epoch=$ts->getTimestamp();
//1364490754
Happy days :)

易百教程