首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

DateTimeZone::getOffset

(PHP 5 >= 5.2.0, PHP 7)

DateTimeZone :: getOffset - timezone_offset_get - 返回GMT的时区偏移量

Description

面向对象的风格

代码语言:javascript
复制
public int DateTimeZone::getOffset ( DateTime $datetime )

程序风格

代码语言:javascript
复制
int timezone_offset_get ( DateTimeZone $object , DateTime $datetime )

该函数返回datetime参数中指定日期/时间的GMT偏移量。GMT偏移量是使用包含在正在使用的DateTimeZone对象中的时区信息计算的。

Parameters

代码语言:txt
复制
`object`   

仅限过程样式:由timezone_open()返回的DateTimeZone对象

datetime

包含计算距离偏移的日期/时间的DateTime。

Return Values

以秒为单位返回成功或FALSE失败,。

Examples

Example #1 DateTimeZone::getOffset() examples

代码语言:javascript
复制
<?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 →

代码语言:txt
复制
 ? 1997–2017 The PHP Documentation Group

根据知识共享署名许可证v3.0或更高版本授权。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com