Copyright © tutorialspoint.com

PHP Function timezone_offset_get()

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

Paramters

ParameterDescription
objectRequired. A date and time zone object
datetimeRequired. 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 following result:

int(32400)
previous

Copyright © tutorialspoint.com