DateTime::getOffset
DateTimeImmutable::getOffset
DateTimeInterface::getOffset
date_offset_get
(PHP 5 >= 5.2.1, PHP 7, PHP 8)
DateTime::getOffset -- DateTimeImmutable::getOffset -- DateTimeInterface::getOffset -- date_offset_get — Returns the timezone offset
說明
物件導向風格
public DateTime::getOffset(): int
public DateTimeImmutable::getOffset(): int
public DateTimeInterface::getOffset(): int
過程化風格
Returns the timezone offset.
參數
-
object
-
僅為過程化風格:由 date_create() 返回的 DateTime 型別的對象。
返回值
Returns the timezone offset in seconds from UTC on success.
更新日誌
版本 | 說明 |
---|---|
8.0.0 |
Prior to this version, false was returned on failure.
|
範例
示例 #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 date_offset_get($winter) . "\n";
echo date_offset_get($summer) . "\n";
?>
以上例程會輸出:
-18000 -14400
Note: -18000 = -5 hours, -14400 = -4 hours.