DateTimeZone::getOffset
(PHP 5 >= 5.2.0, PHP 7)
DateTimeZone :: getOffset - timezone_offset_get - 返回GMT的时区偏移量
Description
面向对象的风格
public int DateTimeZone::getOffset ( DateTime $datetime )
程序风格
int timezone_offset_get ( DateTimeZone $object , DateTime $datetime )
该函数返回datetime
参数中指定日期/时间的GMT偏移量。GMT偏移量是使用包含在正在使用的DateTimeZone对象中的时区信息计算的。
Parameters
`object`
仅限过程样式:由timezone_open()返回的DateTimeZone对象
datetime
包含计算距离偏移的日期/时间的DateTime。
Return Values
以秒为单位返回成功或FALSE
失败,。
Examples
Example #1 DateTimeZone::getOffset() examples
<?php
//?Create?two?timezone?objects,?one?for?Taipei?(Taiwan)?and?one?for
//?Tokyo?(Japan)
$dateTimeZoneTaipei?=?new?DateTimeZone("Asia/Taipei");
$dateTimeZoneJapan?=?new?DateTimeZone("Asia/Tokyo");
//?Create?two?DateTime?objects?that?will?contain?the?same?Unix?timestamp,?but
//?have?different?timezones?attached?to?them.
$dateTimeTaipei?=?new?DateTime("now",?$dateTimeZoneTaipei);
$dateTimeJapan?=?new?DateTime("now",?$dateTimeZoneJapan);
//?Calculate?the?GMT?offset?for?the?date/time?contained?in?the?$dateTimeTaipei
//?object,?but?using?the?timezone?rules?as?defined?for?Tokyo
//?($dateTimeZoneJapan).
$timeOffset?=?$dateTimeZoneJapan->getOffset($dateTimeTaipei);
//?Should?show?int(32400)?(for?dates?after?Sat?Sep?8?01:00:00?1951?JST).
var_dump($timeOffset);
?>
← DateTimeZone::getName
DateTimeZone::getTransitions →
? 1997–2017 The PHP Documentation Group
根据知识共享署名许可证v3.0或更高版本授权。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com