PHP 7.4.13 Released!

MongoDB\BSON\UTCDateTime::__construct

(mongodb >=1.0.0)

MongoDB\BSON\UTCDateTime::__constructConstruct a new UTCDateTime

Açıklama

final public MongoDB\BSON\UTCDateTime::__construct ([ int|float|string|DateTimeInterface $milliseconds = NULL ] )

Değiştirgeler

milliseconds (int|float|string|DateTimeInterface)

Number of milliseconds since the Unix epoch (Jan 1, 1970). Negative values represent dates before 1970. This value may be provided as a 64-bit int. For compatibility on 32-bit systems, this parameter may also be provided as a float or string.

If the argument is a DateTimeInterface, the number of milliseconds since the Unix epoch will be derived from that value. Note that in versions of PHP versions before 7.1.0, DateTime and DateTimeImmutable objects constructed from the current time did not incorporate sub-second precision.

If this argument is NULL, the current time will be used by default.

Hatalar/İstisnalar

Sürüm Bilgisi

Sürüm: Açıklama
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.

Örnekler

Örnek 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));

?>

Yukarıdaki örnek şuna benzer bir çıktı üretir:

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"
}

Ayrıca Bakınız

add a note add a note

User Contributed Notes 3 notes

up
0
0xff00ff at gmail dot com
4 years ago
$utcdatetime = new MongoDB\BSON\UTCDateTime($unixtimestamp * 1000);
up
0
jesperbendtsen83 at gmail dot com
4 years ago
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');
up
-1
jesperbendtsen83 at gmail dot com
4 years ago
The problem with integer => string is only on 32 bit systems
To Top