• PHP Video Tutorials

PHP timezone_offset_get() Function



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)

Parameters

Sr.No Parameter & Description
1

object (Mandatory)

This is a DateTimeZone object.

2

datetime (Mandatory)

This is a DateTimeInterface object specifying the date/time for which you need to compute the offset.

Return Values

PHP timezone_offset_get() function returns a integer value specifying the required timezone offset in seconds.Incase of failure, this function returns the boolean value false.

PHP Version

This function was first introduced in PHP Version 5.2.0 and, works with all the later versions.

Example

Following example demonstrates the usage of the timezone_offset_get() function −

Live Demo
<?php
   $tz = new DateTimeZone("Indian/mahe");
   $datetime = date_create("now", new DateTimeZone("Asia/Taipei"));
   $res = timezone_offset_get($tz, $datetime );
   print($res);
?>

This will produce following result −

14400

Example

$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);

This will produce the following result −

int(32400)
php_function_reference.htm
Advertisements