PHP.mk документација

MongoDB\BSON\UTCDateTime

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

class.mongodb-bson-utcdatetime.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека class.mongodb-bson-utcdatetime.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
MongoDB\BSON\UTCDateTime

Референца за `class.mongodb-bson-utcdatetime.php` со подобрена типографија и навигација.

class.mongodb-bson-utcdatetime.php

The MongoDB\BSON\UTCDateTime class

класата MongoDB\Driver\BulkWrite

Вовед

Represents a » BSON date. The value is a 64-bit integer that represents the number of milliseconds since the Unix epoch (Jan 1, 1970). Negative values represent dates before 1970.

Синопсис на класата

final class MongoDB\BSON\UTCDateTime implements MongoDB\BSON\UTCDateTimeInterface, MongoDB\BSON\Type, JsonSerializable, Serializable {
/* Методи */
final public jsonSerialize(): mixed
final public toDateTime(): DateTime
final public __toString(): string
}

Дневник на промени

Верзија = NULL
(mongodb >=1.3.0)

» mapReduce Countable interface.

Оваа класа повеќе не имплементира PECL mongodb 1.12.0 Serializable Имплементира
за PHP 8.0+. PECL mongodb 1.12.0 MongoDB\BSON\UTCDateTimeInterface.
PECL mongodb 1.3.0 PECL mongodb 1.12.0 Countable and JsonSerializable.

Содржина

Белешки од корисници 3 белешки

Стивен
пред 7 години
When using MongoDB\BSON\UTCDateTime to query be sure for instances of strtotime you are putting the constructor in milliseconds:

$start = new MongoDB\BSON\UTCDateTime(strtotime("midnight") * 1000);
$filter = ['date' => ['$gte' => $start]];
$options = ['sort' => ['date' => -1]];
$query = new MongoDB\Driver\Query($filter,$options);
mark at DONTSPAM dot moderndeveloperllc dot com
пред 9 години
Be careful using UTCDateTime if you need microsecond precision as this class only stores time to the _millisecond_. You need to store the date as a string in MongoDB if you want the full precision. Casting DateTime to a float can also remove precision.

An easy way to see the differences is with:

Code:
var_dump(
  (new DateTime)->format('U.u'), 
  (float) (new DateTime)->format('U.u'), 
  (new MongoDB\BSON\UTCDateTime())->toDateTime()->format('U.u')
);

Output:
string(17) "1477534060.918415"
double(1477534060.9185)
string(17) "1477534060.918000"

NOTE: Lots of bugs concerning microsecond formatting for DateTimeInterface classes were fixed as of PHP 7.1.0 RC4. The above code is from PHP 7.1.0 RC5 and mongodb 1.2.0alpha3. The 1.2.0 version of the extension added the ability to instantiate this class without passing integer milliseconds.
mike at brenden dot com
пред 8 години
SOURCE [url]https://github.com/mongodb/mongo-php-driver/issues/187[/url]

MichaelBrenden --

How do the two Mongo drivers determine if they can translate something into the ISODate format?

Does mongo.so require a class type of MongoDate, or does it determine by data returned by __toString() (i.e., "0.12345678 1234567890")?

Does mongodb.so require a class type of \MongoDB\BSON\UTCDateTime, or does it determine by data returned by __toString() (i.e., "1234567890123")?

jmikola --

>> the ISODate format?

For the record, ISODate is just a helper function in the mongo shell. The actual BSON type is 0x09 in the BSON spec and is best referred to as "UTC date time".
[url]https://docs.mongodb.com/manual/core/shell-types/#return-date[/url]
[url]http://bsonspec.org/spec.html[/url]

 >> Does mongodb.so require a class type of \MongoDB\BSON\UTCDateTime, or does it determine by data returned by __toString() (i.e., "1234567890123")?

The driver requires a MongoDB\BSON\UTCDateTime object in order to encode a BSON date type. The relevant instanceof check during BSON encoding is here if you care to see it. The __toString() function exists purely as a convenience for userland applications. The driver does not use it outside of tests.
[url]https://github.com/mongodb/mongo-php-driver/blob/1.3.4/src/bson-encode.c#L215[/url]

The legacy mongo.so driver is similar in that it requires a MongoDate object in order to encode a BSON date type (relevant code is here).
[url]https://github.com/mongodb/mongo-php-driver-legacy/blob/1.6.16/bson.c#L273[/url]
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.