array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'datetime.gettimezone.php', 1 => 'DateTimeInterface::getTimezone', ), 'up' => array ( 0 => 'class.datetimeinterface.php', 1 => 'DateTimeInterface', ), 'prev' => array ( 0 => 'datetime.gettimestamp.php', 1 => 'DateTimeInterface::getTimestamp', ), 'next' => array ( 0 => 'datetime.wakeup.php', 1 => 'DateTime::__wakeup', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/datetime/datetimeinterface/gettimezone.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5 >= 5.2.0, PHP 7, PHP 8)
DateTimeInterface::getTimezone -- DateTimeImmutable::getTimezone -- DateTime::getTimezone -- date_timezone_get — 返回相对于指定 DateTime 的时区
面向对象风格
过程化风格
返回相对于指定 DateTime 的时区。
object
仅为过程化风格:由 date_create() 返回的 DateTime 类型的对象。
成功时返回 DateTimeZone 对象 或者在失败时返回 false
。
示例 #1 DateTime::getTimezone() 示例
面向对象风格
<?php
$date = new DateTimeImmutable(null, new DateTimeZone('Europe/London'));
$tz = $date->getTimezone();
echo $tz->getName();
?>
过程化风格
<?php
$date = date_create(null, timezone_open('Europe/London'));
$tz = date_timezone_get($date);
echo timezone_name_get($tz);
?>
以上示例会输出:
Europe/London