PHP | timezone_offset_get() Function

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Open the timezone of America/Chicago
$timezone = timezone_open("America/Chicago");
  
// Displaying the offset of America/Chicago and Europe/Amsterdam
$datetime_eur = date_create("now", timezone_open("Europe/Amsterdam"));
echo timezone_offset_get($timezone, $datetime_eur);
?>

chevron_right


Output:

-18000

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Open the timezone of America/Chicago and Europe/Amsterdam
$timezone_chicago = new DateTimeZone("America/Chicago");
$timezone_amsterdam = new DateTimeZone("Europe/Amsterdam");
     
$chicago = new DateTime("now", $timezone_chicago);
$amsterdam = new DateTime("now", $timezone_amsterdam);
  
// Calculating the offset between the timezones   
$Offset = $timezone_amsterdam -> getOffset($chicago);
  
// Dumping the offset variable
var_dump($Offset);
?>

chevron_right


Output:

int(7200)

Related Articles:

Reference: http://php.net/manual/en/function.timezone-offset-get.php



My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.