PHP | date_timezone_get() Function
Last Updated :
17 Sep, 2018
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:
Parameters: This function accepts single parameter $object which is mandatory in procedural style. It is used to specify the DateTime object which is returned by the date_create() function. The object oriented style does not require any parameter.
Return Value: This function returns a DateTimeZone object on success or False on failure.
Below programs illustrate the date_timezone_get() function in PHP:
Program 1:
<?php
$date = date_create(null, timezone_open( 'Asia/Kolkata' ));
$time_zone = date_timezone_get( $date );
echo timezone_name_get( $time_zone );
?>
|
Program 2:
<?php
$date = new DateTime(null, new DateTimeZone( 'Asia/Kolkata' ));
$time_zone = $date ->getTimezone();
echo $time_zone ->getName();
?>
|
Related Articles:
Reference: http://php.net/manual/en/datetime.gettimezone.php
Share your thoughts in the comments
Please Login to comment...