DateTime
PHP Manual

DateTime::getOffset

(PHP 5 >= 5.2.0)

DateTime::getOffsetReturns the timezone offset

Description

Object oriented style

public int DateTime::getOffset ( void )

Procedural style

int date_offset_get ( DateTime $object )

Returns the timezone offset.

Parameters

object

Procedural style only: A DateTime object returned by date_create()

Return Values

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

Examples

Example #1 DateTime::getOffset() example

Object oriented style

<?php
$winter 
= new DateTime('2010-12-21', new DateTimeZone('America/New_York'));
$summer = new DateTime('2008-06-21', new DateTimeZone('America/New_York'));

echo 
$winter->getOffset() . "\n";
echo 
$summer->getOffset() . "\n";
?>

Procedural style

<?php
$winter 
= new date_create('2010-12-21'timezone_open('America/New_York'));
$summer = new date_create('2008-06-21'timezone_open('America/New_York'));

echo 
$winter->getOffset() . "\n";
echo 
$summer->getOffset() . "\n";
?>

The above examples will output:

-18000
-14400

Note: -18000 = -5 hours, -14400 = -4 hours.


DateTime
PHP Manual