English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP timezone_offset_get() Function Usage and Examples

PHP Date & Time Function Manual

The timezone_offset_get() function returns the time difference relative to GMT.

Definition and Usage

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.

Syntax

timezone_offset_get($object, $datetime)

Parameter

NumberParameters 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.

Return Value

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.

PHP version

This function was originally introduced in PHP version5.2introduced in version 5.3.0 and can be used in all higher versions.

Online Example

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

Online Example

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)