(PHP 5 >= 5.2.1, PHP 7)
DateTime::getTimezone -- DateTimeImmutable::getTimezone -- DateTimeInterface::getTimezone -- date_timezone_get — Return time zone relative to given DateTime
Object oriented style
public DateTime::getTimezone ( ) : DateTimeZone|false
public DateTimeImmutable::getTimezone ( ) : DateTimeZone|false
public DateTimeInterface::getTimezone ( ) : DateTimeZone|false
Procedural style
date_timezone_get ( DateTimeInterface $object ) : DateTimeZone|false
Return time zone relative to given DateTime.
object
Procedural style only: A DateTime object returned by date_create()
Returns a DateTimeZone object on success or false
on failure.
Example #1 DateTime::getTimezone() example
Object oriented style
<?php $date = new DateTime(null, new DateTimeZone('Europe/London')); $tz = $date->getTimezone(); echo $tz->getName(); ?>
Procedural style
<?php $date = date_create(null, timezone_open('Europe/London')); $tz = date_timezone_get($date); echo timezone_name_get($tz); ?>
The above examples will output:
Europe/London
© 1997–2020 The PHP Documentation Group
Licensed under the Creative Commons Attribution License v3.0 or later.
https://www.php.net/manual/en/datetime.gettimezone.php