Deprecated: Optional parameter $keys declared before required parameter $cms_id is implicitly treated as a required parameter in /home/www/dev/work/class/blog/CmsKey.php on line 75

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$title is deprecated in /home/www/dev/work/website/lvesu/class/controller/blog/php.php on line 28

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$outlink is deprecated in /home/www/dev/work/website/lvesu/template/blog/cms/php.manual.tpl on line 2

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$status is deprecated in /home/www/dev/work/website/lvesu/template/blog/index.head.php on line 2
PHP - Manual: MongoDB\BSON\UTCDateTime::__construct - 互联网笔记

略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: MongoDB\BSON\UTCDateTime::__construct

2025-05-19

MongoDB\BSON\UTCDateTime::__construct

(mongodb >=1.0.0)

MongoDB\BSON\UTCDateTime::__constructConstruct a new UTCDateTime

说明

final public MongoDB\BSON\UTCDateTime::__construct(int|float|string|MongoDB\BSON\Int64|DateTimeInterface|null $milliseconds = null)

参数

milliseconds (int|float|string|DateTimeInterface|null)

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 MongoDB\BSON\Int64.

If the argument is a DateTimeInterface, the number of milliseconds since the Unix epoch will be derived from that value.

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

错误/异常

更新日志

版本 说明
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"
}
添加备注

用户贡献的备注 3 notes

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

官方地址:https://www.php.net/manual/en/mongodb-bson-utcdatetime.construct.php

冷却塔厂家 广告
中文GPT4.0无需注册 广告
北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3