$utcdatetime = new MongoDB\BSON\UTCDateTime($unixtimestamp * 1000);(mongodb >=1.0.0)
MongoDB\BSON\UTCDateTime::__construct — Constrói um novo UTCDateTime
$milliseconds = null)milliseconds (int|MongoDB\BSON\Int64|DateTimeInterface|null)null, o horário atual será usado por padrão.
| Versão | Descrição |
|---|---|
| PECL mongodb 2.0.0 |
O parâmetro milliseconds não aceita mais um argumento
string ou float.
|
| PECL mongodb 1.20.0 |
O parâmetro milliseconds agora aceita um objeto
MongoDB\BSON\Int64 (para compatibilidade com
plataformas de 32 bits). Especificar um string ou
um float foi descontinuado.
|
| PECL mongodb 1.2.0 |
O argumento milliseconds é opcional e
o padrão é null (ou seja, horário atual). O argumento também aceita um
DateTimeInterface, que pode ser usado para derivar
o número de milissegundos desde a época Unix. Anteriormente, apenas
os tipos int, float e string
eram aceitos.
|
Exemplo #1 Exemplo de 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));
?>O exemplo acima produzirá algo semelhante a:
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