array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'datetime.construct.php', 1 => 'DateTime::__construct', ), 'up' => array ( 0 => 'class.datetime.php', 1 => 'DateTime', ), 'prev' => array ( 0 => 'datetime.add.php', 1 => 'DateTime::add', ), 'next' => array ( 0 => 'datetime.createfromformat.php', 1 => 'DateTime::createFromFormat', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/datetime/datetime/construct.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5 >= 5.2.0, PHP 7, PHP 8)
DateTime::__construct — 返回新的 DateTime 对象
跟 DateTimeImmutable::__construct() 一样,但适用于 DateTime。Consider using the DateTimeImmutable and features instead.
返回新的 DateTime 对象。
datetime
日期/时间字符串。正确格式的说明详见 日期与时间格式。
如果这个参数为字符串 "now"
表示获取当前时间。
如果同时指定了 $timezone
参数,那么获取指定时区的当前时间。
timezone
DateTimeZone 对象表示
$datetime
的时区。
如果省略了 $timezone
参数或者传递 null
,
那么会使用当前时区。
注意:
当
$datetime
参数是 UNIX 时间戳(例如@946684800
),或者已经包含时区信息(例如2010-01-28T15:00:00+02:00
)的时候,$timezone
参数和当前时区都将被忽略。
返回一个新的 DateTime 对象实例,或者在发生错误的时候返回
如果传递无效的日期/时间字符串,将会抛出 DateMalformedStringException,在 PHP 8.3 之前,将抛出 Exception。