PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

timezone_open> <timezone_name_get
Last updated: Fri, 09 May 2008

view this page in

timezone_offset_get

(PHP 5 >= 5.1.0)

timezone_offset_get — GMT からのタイムゾーンのオフセットを返す

説明

int timezone_offset_get ( DateTimeZone $object , DateTime $datetime )
int DateTimeZone::getOffset ( DateTime $datetime )

この関数は、datetime パラメータで指定した 日付/時刻 についての GMT へのオフセットを返します。GMT オフセットの計算の際には、 使用する DateTime オブジェクトに含まれるタイムゾーン情報を使用します。

パラメータ

object

DateTimeZone オブジェクト。

datetime

オフセットを計算する 日付/時刻 を含む DateTime。

返り値

成功した場合にタイムゾーンのオフセット秒数、失敗した場合に FALSE を返します。

例1 timezone_offset_get() の例

<?php
// ふたつのタイムゾーンオブジェクトを作成します。ひとつは台北 (台湾)、
// そしてもうひとつは東京 (日本) のものです。
$dateTimeZoneTaipei = new DateTimeZone("Asia/Taipei");
$dateTimeZoneJapan = new DateTimeZone("Asia/Tokyo");

// 同一の Unix タイムスタンプを持つふたつの DateTime オブジェクトを作成します。
// しかしアタッチするタイムゾーンはそれぞれ異なります。
$dateTimeTaipei = new DateTime("now"$dateTimeZoneTaipei);
$dateTimeJapan = new DateTime("now"$dateTimeZoneJapan);

// $dateTimeTaipei オブジェクトに含まれる 日付/時刻 の GMT オフセットを計算します。
// しかし、タイムゾーンの規則は東京のもの ($dateTimeZoneJapan)
// を使用します。
$timeOffset $dateTimeZoneJapan->getOffset($dateTimeTaipei);

// これは int(32400) となります (Sat Sep 8 01:00:00 1951 JST 以降の日付の場合)。
var_dump($timeOffset);
?>



add a note add a note User Contributed Notes
timezone_offset_get
richard at phase dot org
20-Mar-2007 04:05
The following extended example may make the usage clearer;
<?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);

// NOTE: $dateTimeJapan is not used further in this example

// 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).
print("Number of seconds Japan is ahead of GMT at the specific time: ");
var_dump($timeOffset);

print(
"<br />Number of seconds Taipei is ahead of GMT at the specific time: ");
var_dump($dateTimeZoneTaipei->getOffset($dateTimeTaipei));

print(
"<br />Number of seconds Japan is ahead of Taipei at the specific time: ");
var_dump($dateTimeZoneJapan->getOffset($dateTimeTaipei)
     -
$dateTimeZoneTaipei->getOffset($dateTimeTaipei));

print(
"<hr />");

?>

Number of seconds Japan is ahead of GMT at the specific time: int(32400)
Number of seconds Taipei is ahead of GMT at the specific time: int(28800)
Number of seconds Japan is ahead of Taipei at the specific time: int(3600)

timezone_open> <timezone_name_get
Last updated: Fri, 09 May 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites