$utcdatetime = new MongoDB\BSON\UTCDateTime($unixtimestamp * 1000);
(mongodb >=1.0.0)
MongoDB\BSON\UTCDateTime::__construct — 建構新的 UTCDateTime
$milliseconds
= null
)milliseconds
參數 (整數 (int)|浮點數 (float)|字串 (string)|DateTimeInterface|null)自 Unix 紀元 (1970 年 1 月 1 日) 以來的毫秒數。負值表示 1970 年之前的日期。此值可以提供為 64 位元 整數。為了在 32 位元系統上的相容性,此參數也可以提供為 MongoDB\BSON\Int64 物件。
如果參數是 DateTimeInterface,則會從該值衍生自 Unix 紀元以來的毫秒數。
如果此參數為 null
,則預設會使用目前時間。
版本 | 說明 |
---|---|
PECL mongodb 1.20.0 |
|
PECL mongodb 1.2.0 |
|
範例 #1 MongoDB\BSON\UTCDateTime::__construct() 範例
<?php
var_dump(new MongoDB\BSON\UTCDateTime);
var_dump(new MongoDB\BSON\UTCDateTime(new DateTime));
var_dump(new MongoDB\BSON\UTCDateTime(1416445411987));
?>
上述範例將輸出類似以下的內容
object(MongoDB\BSON\UTCDateTime)#1 (1) { ["milliseconds"]=> string(13) "1484852905560" } object(MongoDB\BSON\UTCDateTime)#1 (1) { ["milliseconds"]=> string(13) "1484852905560" } object(MongoDB\BSON\UTCDateTime)#1 (1) { ["milliseconds"]=> string(13) "1416445411987" }
在我的 IIS 7.5 上使用 PHP 5.6 時,必須使用字串格式才能正常運作。
$utcdatetime = new MongoDB\BSON\UTCDateTime('1416445411987');