+

PHP Timezone_offset_get () function

Syntax:
int timezone_offset_get ($object, $datetime)
Parameters:This function takes two parameters, as above and described below:
  • $object:This is a required parameter that specifies a DateTimeZone object.
  • $datetime: is also a required parameter that specifies the date / time from which to calculate the offset.
Returned value:returns the timezone offset in seconds on success or False on error.Exceptions:The timezone_offset_get() function is an alias for the DateTimeZone::getOffset() function.The following programs illustrate the timezone_offset_get() function in PHP:Program 1:  
// Open America / Chicago time zone $timezone = timezone_open ( "America / Chicago" );  
// Displays the offset of America / Chicago and Europe / Amsterdam $datetime_eur = date_create ( "now" , timezone_open ( "Europe / Amsterdam" )); echo timezone_offset_get ( $timezone , $datetime_eur ); ?>
Exit:
-18000 < / pre> Program 2:        
// Open America / Chicago and Europe / Amsterdam time zone $timezone_chicago = new DateTimeZone ( "America / Chicago" ); $timezone_amsterdam = new DateTimeZone ( "Europe / Amsterdam" ); $chicago = new DateTime ( " now " , $timezone_chicago ); $amsterdam = new DateTime ( "now" , $timezone_amsterdam );  
// Calculate the offset between time zones $Offset = $timezone_amsterdam -> getOffset ( $chicago );  
// Reset the offset variable var_dump ( $Offset ); ?>
Exit:
int (7200 )
Related Articles:
  • PHP | Timezone_location_get() function
  • PHP | Timezone_open() function
  • PHP | Timezone_name_from_abbr() function
Link: http://php.net/manual/en/function.timezone-offset-get.php
Get Solution for free from DataCamp guru