Php/docs/datetime.gettimezone
DateTime::getTimezone
DateTimeImmutable::getTimezone
DateTimeInterface::getTimezone
date_timezone_get
(PHP 5 >= 5.2.1, PHP 7)
DateTime::getTimezone -- DateTimeImmutable::getTimezone -- DateTimeInterface::getTimezone -- date_timezone_get — Return time zone relative to given DateTime
说明
面向对象风格
public DateTime::getTimezone ( ) : DateTimeZone|false
public DateTimeImmutable::getTimezone ( ) : DateTimeZone|false
public DateTimeInterface::getTimezone ( ) : DateTimeZone|false
过程化风格
date_timezone_get
( DateTimeInterface $object
) : DateTimeZone|false
Return time zone relative to given DateTime.
范例
Example #1 DateTime::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