(PHP 5 >= 5.2.0)
DateTime::getOffset — Returns the timezone offset
面向对象风格
过程化风格
Returns the timezone offset.
仅为过程化风格:由 date_create() 返回的 DateTime 类型的对象。
Returns the timezone offset in seconds from UTC on success 或者在失败时返回 FALSE.
Example #1 DateTime::getOffset() example
面向对象风格
<?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";
?>
过程化风格
<?php
$winter = date_create('2010-12-21', timezone_open('America/New_York'));
$summer = date_create('2008-06-21', timezone_open('America/New_York'));
echo $winter->getOffset() . "\n";
echo $summer->getOffset() . "\n";
?>
以上例程会输出:
-18000 -14400
Note: -18000 = -5 hours, -14400 = -4 hours.