DateTimeInterface::getTimezone
PHP function
Edit on GitHub ✎
(PHP 5 >= 5.2.0, PHP 7, PHP 8)
Return time zone relative to given DateTime
Description
Oop
DateTimeInterface::getTimezone(): DateTimeZone|false
DateTimeImmutable::getTimezone(): DateTimeZone|false
DateTime::getTimezone(): DateTimeZone|false
Procedural
date_timezone_get(DateTimeInterface $object): DateTimeZone|false
Return time zone relative to given DateTime.
Parameters
Return Values
Returns a DateTimeZone object on success Falseforfailure.
Examples
DateTime::getTimezone() example
Oop
php
<?php
$date = new DateTimeImmutable("now", new DateTimeZone('Europe/London'));
$tz = $date->getTimezone();
echo $tz->getName();The above example will output:
output
Europe/LondonProcedural
php
<?php
$date = date_create("now", timezone_open('Europe/London'));
$tz = date_timezone_get($date);
echo timezone_name_get($tz);The above example will output:
output
Europe/London