DateTime::getTimezone()
DateTimeImmutable::getTimezone
DateTimeInterface::getTimezone
date_timezone_get
(PHP 5 >= 5.2.1, PHP 7)
Return time zone relative to given DateTime
说明
面向对象风格public DateTime::getTimezone(void): DateTimeZone
public DateTimeImmutable::getTimezone(void): DateTimeZone
public DateTimeInterface::getTimezone(void): DateTimeZone
过程化风格
date_timezone_get(DateTimeInterface$object): DateTimeZone
Return time zone relative to given DateTime.
参数
- $object
仅为过程化风格:由date_create()返回的DateTime类型的对象。
返回值
Returns aDateTimeZoneobject on success 或者在失败时返回FALSE.
范例
Example #1DateTime::getTimezone()example
面向对象风格
<?php
$date = new DateTime(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
参见
- DateTime::setTimezone() 设置 DateTime 对象的时区
