PHP | date_timezone_get() Function
Last Updated :
17 Sep, 2018
Improve
The date_timezone_get() function is an inbuilt function in PHP which is used to return time zone relative to given DateTime. This function returns a DateTimeZone object on success or False on failure.
Syntax:
php
php
- Procedural style:
date_timezone_get( $object )
- Object oriented style:
DateTime::getTimezone( void ) DateTimeImmutable::getTimezone( void ) DateTimeInterface::getTimezone( void )
<?php
// Create DateTime object
$date = date_create(null, timezone_open('Asia/Kolkata'));
// Return the timezone of given DateTime
$time_zone = date_timezone_get($date);
// Return the DateTimeZone object
echo timezone_name_get($time_zone);
?>
Output:
Program 2:
Asia/Kolkata
<?php
// Create DateTime object using DateTimeZone
$date = new DateTime(null, new DateTimeZone('Asia/Kolkata'));
// Return the timezone of given DateTime
$time_zone = $date->getTimezone();
// Return the DateTimeZone object
echo $time_zone->getName();
?>
Output:
Related Articles:
Reference: http://php.net/manual/en/datetime.gettimezone.php
Asia/Kolkata