2017-08-05 6 views
-2

私はすべてのタイムゾーンを取得しようとしています。私が行っていることである。すべてのタイムゾーンを取得

Array 
(
    [0] => Africa/Abidjan 
    [1] => Africa/Accra 
    [2] => Africa/Addis_Ababa 
    [3] => Africa/Algiers 
    [4] => Africa/Asmara 
    [5] => Africa/Bamako 
    [6] => Africa/Bangui 
    [7] => Africa/Banjul 
    [8] => Africa/Bissau.... 

は、私はすべてのタイムゾーン 例えばのための完全なタイムゾーン名にタイムゾーンの名前を変更したい:

$tzlist = DateTimeZone::listIdentifiers(DateTimeZone::ALL);

それは私にこのような配列を与えます

Australia/Darwin = AUS Central Standard Time 

は、Microsoft Windowsのタイムゾーン(here)のIDであるあなたが求めている例here

+0

を私が改善することができるように質問をdownvotingている者はコメントしてください同じ –

+1

私はdownvoteしなかったが、質問/問題は何ですか? – Andreas

+0

@アンドレアスすべてのタイムゾーンの 'AUS Central Standard Time 'のような' Australia/Darwin'フルネームのようなタイムゾーンを欲しい –

答えて

2

IntlTimeZone::getDisplayName()を使用できます。:

echo IntlTimeZone::createTimeZone("Australia/Darwin")->getDisplayName(); 

出力:

Australian Central Standard Time 

多くは、夏時間のために、年間を通じて変化しますけど。出力

$tz = IntlTimeZone::createTimeZone("America/Los_Angeles"); 
echo $tz->getDisplayName(), "\n"; 
if ($tz->useDaylightTime()) { 
    echo $tz->getDisplayName(true); 
} 

:あなたはこれをチェックし、代替デイライト/夏の表示名を追加したい場合は、あなたのような何かを行うことができます

Pacific Standard Time 
Pacific Daylight Time 
+0

それは私が探していた答え:) –

+1

@PradeepSingh - 本当ですか? [このコメント](https://stackoverflow.com/questions/45521276/get-all-timezones#comment78003673_45521624)では、ウィンドウズIDが必要であることを確認しました。これは、これらのロケール固有の表示名(CLDRに由来)とは異なります。どちらですか? –

+0

@MattJohnsonはい、私は同じものが欲しいですが、私はそれが何であるかを確認していませんでした。 –

0

を見ることができます。 PHPはIANA/Olsonタイムゾーンを使用します。詳細は、timezone tag wikiを参照してください。

PHP official documentationから、あなたはこれを試すことができます。

<?php 

$timezones = DateTimeZone::listAbbreviations(); 

$cities = array(); 
foreach($timezones as $key => $zones) 
{ 
    foreach($zones as $id => $zone) 
    { 
     /** 
     * Only get timezones explicitely not part of "Others". 
     * @see http://www.php.net/manual/en/timezones.others.php 
     */ 
     if (preg_match('/^(America|Antartica|Arctic|Asia|Atlantic|Europe|Indian|Pacific)\//', $zone['timezone_id'])) 
      $cities[$zone['timezone_id']][] = $key; 
    } 
} 

// For each city, have a comma separated list of all possible timezones for that city. 
foreach($cities as $key => $value) 
    $cities[$key] = join(', ', $value); 

// Only keep one city (the first and also most important) for each set of possibilities. 
$cities = array_unique($cities); 

// Sort by area/city name. 
ksort($cities); 

?> 

ここでは、別のSOあなたが見ることができるという疑問、同様の答えがたくさんある:これのどれも助けていない場合はGenerating a drop down list of timezones with PHP

、あなたが試すことができますあなたのタイムゾーンにデータをconvertに上のコード。たとえば、ACST(オーストラリア中央標準時)に変換するUTCの日付と時刻の文字列(2017-08-05 02:45)があるとします。

<?php 
$utc_date = DateTime::createFromFormat(
    'Y-m-d G:i', 
    '2017-08-05 02:45', 
    new DateTimeZone('UTC') 
); 

$acst_date = clone $utc_date; // we don't want PHP's default pass object by reference here 
$acst_date->setTimeZone(new DateTimeZone('Australia/Yancowinna')); 

echo 'UTC: ' . $utc_date->format('Y-m-d g:i A'); // UTC: 2017-08-05 02:45 AM 
echo 'ACST: ' . $acst_date->format('Y-m-d g:i A'); // ACST: 2017-08-05 14:15 PM 

希望すると助かります!

UPDATE:

From here、あなたがPHPに、WindowsのIDSのタイムゾーンを持っている:

AUS中央標準時、1、オーストラリア/ダーウィン AUS中央標準時、AU、オーストラリア/ダーウィン AUS東部標準時、1、オーストラリア/シドニー AUS東部標準時、オーストラリア、オーストラリア/オーストラリア オーストラリア東部標準時オーストラリア/オーストラリア

Pアレイ:

$timezonesArray = 
['AUS Central Standard Time','1','Australia/Darwin', 
'AUS Central Standard Time','AU','Australia/Darwin', 
'AUS Eastern Standard Time','1','Australia/Sydney', 
'AUS Eastern Standard Time','AU','Australia/Melbourne', 
'AUS Eastern Standard Time','AU','Australia/Sydney', 
'Afghanistan Standard Time','1','Asia/Kabul', 
'Afghanistan Standard Time','AF','Asia/Kabul',, 
'Alaskan Standard Time','1','America/Anchorage', 
'Alaskan Standard Time','US','America/Anchorage', 
'Alaskan Standard Time','US','America/Juneau', 
'Alaskan Standard Time','US','America/Nome', 
'Alaskan Standard Time','US','America/Sitka', 
'Alaskan Standard Time','US','America/Yakutat']; 
//... the array continues 

、その後、あなたの希望の窓のID(配列位置[0])、検索またはものは何でもしたいとして、あなたのタイムゾーン(配列位置2)を変換する機能を行うことができます。

それは私が推測するよりエレガントな解決策ではありませんが、それは動作し、そのシンプルです。配列を検索し、必要なtranslationをあるコード化から他のコード化に戻すことができます。

今、幸せなコーディングに役立つことを願っています!

+0

はい@JP .Aulet、WindowsタイムゾーンのIDが必要なので、オーストラリア/ダーウィン=> AUSセントラル標準時 オーストラリア/メルボルン=> AUS東部標準時間 オーストラリア/シドニー=> AUS東部標準時 アジア/カブール=>アフガニスタン標準時 アメリカ/アンカレッジ=>アラスカ標準時 –

関連する問題