PHP | timezone_offset_get() Function
Last Updated :
16 Aug, 2018
The timezone_offset_get() function is an inbuilt function in PHP which is used to return the timezone offset from GMT. The date time object and the date-time are sent as a parameter to the timezone_offset_get() function and return the timezone offset in seconds on success or False on failure.
Syntax:
int timezone_offset_get( $object, $datetime )
Parameters: This function accepts two parameter as mentioned above and described below:
- $object: It is a mandatory parameter which specifies the DateTimeZone object.
- $datetime: It is also a mandatory parameter which specifies the date/time from which the offset has to be computed.
Return Value: It returns the timezone offset in seconds on success or False on failure.
Exceptions: The timezone_offset_get() function is an alias of DateTimeZone::getOffset() function.
Below programs illustrate the timezone_offset_get() function in PHP:
Program 1:
<?php
$timezone = timezone_open( "America/Chicago" );
$datetime_eur = date_create( "now" , timezone_open( "Europe/Amsterdam" ));
echo timezone_offset_get( $timezone , $datetime_eur );
?>
|
Program 2:
<?php
$timezone_chicago = new DateTimeZone( "America/Chicago" );
$timezone_amsterdam = new DateTimeZone( "Europe/Amsterdam" );
$chicago = new DateTime( "now" , $timezone_chicago );
$amsterdam = new DateTime( "now" , $timezone_amsterdam );
$Offset = $timezone_amsterdam -> getOffset( $chicago );
var_dump( $Offset );
?>
|
Related Articles:
Reference: http://php.net/manual/en/function.timezone-offset-get.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...