English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP 基础教程

PHP 高级教程

PHP & MySQL

PHP 参考マニュアル

PHP timezone_open() 函数の用法と例

PHP Date & Time 函数マニュアル

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);
?>
テストを見て‹/›

出力結果:

新しい時帯は アメリカ/シカゴ
新しい時帯は アメリカ/シカゴ