English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP Date & Time Function Manual
The timezone_offset_get() function returns the time difference relative to GMT.
The timezone_offset_get() function is an alias of DateTimeZone::getOffset(). It accepts timezone and datetime values as parameters and returns the timezone offset from GMT.
timezone_offset_get($object, $datetime)
Number | Parameters and Description |
---|---|
1 | object (required) This is a DateTimeZone object. |
2 | datetime (required) This is a DateTimeInterface object, which is used to calculate the time difference of the date object. |
PHP timezone_offset_get() function returns an integer value specifying the required timezone offset in seconds. If it fails, this function returns a boolean valuefalse.
This function was originally introduced in PHP version5.2introduced in version 5.3.0 and can be used in all higher versions.
The following examples demonstratetimezone_offset_get()Function returns timezone offset relative to GMT:-
<?php /mahe $datetime = date_create("now", new DateTimeZone("Asia/Shanghai")); $res = timezone_offset_get($tz, $datetime); print($res); ?>Test and see‹/›
Output Result
14400
Return timezone offset relative to GMT using object-oriented method
<?php $dateTimeZoneTaipei = new DateTimeZone("Asia/Taipei); $dateTimeZoneJapan = new DateTimeZone("Asia/Tokyo); $dateTimeTaipei = new DateTime("now", $dateTimeZoneTaipei); $dateTimeJapan = new DateTime("now", $dateTimeZoneJapan); $timeOffset = $dateTimeZoneJapan->getOffset($dateTimeTaipei); var_dump($timeOffset); ?>Test and see‹/›
Output Result:
int(32400)