$utcdatetime = new MongoDB\BSON\UTCDateTime($unixtimestamp * 1000);(mongodb >=1.0.0)
MongoDB\BSON\UTCDateTime::__construct — Construct a new UTCDateTime
$milliseconds = null)milliseconds (int|MongoDB\BSON\Int64|DateTimeInterface|null)null, the current time will be used by default.
| バージョン | 説明 |
|---|---|
| PECL mongodb 2.0.0 |
The milliseconds no longer accepts a
string or float argument.
|
| PECL mongodb 1.20.0 |
The milliseconds argument now accepts a
MongoDB\BSON\Int64 object (for compatibility on
32-bit platforms). Specifying a string or
float is deprecated.
|
| PECL mongodb 1.2.0 |
The milliseconds argument is optional and
defaults to null (i.e. current time). The argument also accepts a
DateTimeInterface, which may be used to derive
the number of milliseconds since the Unix epoch. Previously, only
int, float, and string types
were accepted.
|
例1 MongoDB\BSON\UTCDateTime::__construct() example
<?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"
}
$utcdatetime = new MongoDB\BSON\UTCDateTime($unixtimestamp * 1000);For me to get it work with php 5.6 on an iis 7.5, it had to be a string
$utcdatetime = new MongoDB\BSON\UTCDateTime('1416445411987');The problem with integer => string is only on 32 bit systems