English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
timezone_open()関数は新しいDateTimeZoneオブジェクトを作成します
timezone_open()関数はDateTimeZone::__construct()の別名です。時区文字列を引数に受け取り、DateTimeZoneオブジェクトを作成します。
timezone_open($timezone)
パラメータ | 番号 |
---|---|
1 | パラメータ及び説明 時帯 (必須) |
返り値timezone_name_get()関数はDateTimeZoneオブジェクトを返します。失敗すると、この関数は布尔値を返します。false
PHPバージョン5.2PHPバージョン5.2.0で導入され、すべてのより高いバージョンで使用できます。
以下の例では、timezone_open();関数の使い方-
<?php $tz = "Indian/mahe"; $res = timezone_open($tz); print_r($res); ?>テストを見て‹/›
出力結果
DateTimeZone Object ( [timezone_type] => 3 [timezone] => Indian/mahe )
新しい DateTimeZone オブジェクトを作成し、その時帯の名前を返します:
<?php $dateSrc = '2017-06-25 1:50 GMT'; $dateTime = date_create( $dateSrc); $DateTimeZone = timezone_open ( 'America';/Chicago'); date_timezone_set( $dateTime, $DateTimeZone ); $NewDateTimeZone = date_timezone_get($dateTime); echo '新しい時帯は '. timezone_name_get($NewDateTimeZone); echo "\n"; # 使用第二种方法 $dateTime = new DateTime($dateSrc); $DateTimeZone = new DateTimeZone( 'America';/Chicago'); $dateTime-setTimezone( $DateTimeZone ); $NewDateTimeZone = $dateTime;-getTimezone (); echo '新しい時帯は '. timezone_name_get ($NewDateTimeZone); ?>テストを見て‹/›
出力結果:
新しい時帯は アメリカ/シカゴ 新しい時帯は アメリカ/シカゴ