PHP - Function timezone_offset_get()


Advertisements


Syntax

int timezone_offset_get ( $object,  $datetime );

int DateTimeZone::getOffset ( $datetime );

Definition and Usage

These functions return the timezone offset from GMT.

The above two functions are equivalent and any of the functions can be used as shown below in the example.

Parameters

Sr.No Parameter & Description
1

object

Required. A date and time zone object

2

datetime

Required. DateTime that contains the date/time to compute the offset from.

Return Value

Returns time zone offset in seconds on success or FALSE on failure.

Example

Following is the usage of this function −

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

This will produce the following result −

int(32400)

php_function_reference.htm

Advertisements