Menu Home

date_offset_get

osbo.com | PHP | Functions | date_offset_get

Returns the timezone offset

Syntax

date_offset_get ( DateTimeInterface $object ) : int

Parameters

object

A DateTime object returned by date_create()

Return

Returns the timezone offset in seconds from UTC on success or FALSE on failure.

Examples

1

<?

$object = date_create();

$return = date_offset_get($object);

echo $return;

?>
0

2

<?

$datetime = "now";
$timezone = timezone_open("America/New_York");

$object = date_create($datetime, $timezone);

$return = date_offset_get($object);

echo $return;

?>
-14400

3

<?

$datetime1 = "2001-01-01";
$datetime2 = "2001-07-01";
$timezone = timezone_open("America/New_York");

$object1 = date_create($datetime1, $timezone);
$object2 = date_create($datetime2, $timezone);

$return1 = date_offset_get($object1);
$return2 = date_offset_get($object2);

echo $return1 . PHP_EOL;
echo $return2;

?>
-18000
-14400

PHP