你所要求的Microsoft Windows時區(here)的標識。 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
數據添加到您的時區。例如,讓我們假設我們有一個UTC日期和時間字符串(2017-08-05 02:45),我們希望將其轉換爲ACST(澳大利亞中部標準時間)。
<?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,你有一個Windows IDS時區到PHP:
澳大利亞中部標準時間1,澳大利亞/達爾文 澳大利亞中部標準時間,AU,澳大利亞/達爾文 AUS東部標準時間1,澳大利亞/悉尼 澳大利亞東部標準時間,AU,澳大利亞/墨爾本 澳大利亞東部標準時間,AU,澳大利亞/悉尼
變化的pH 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
,然後你可以做一個功能,你的時區(陣列位置2)與所需的窗口ID(陣列位置[0]),與find或任何你想要的翻譯。
這不是我猜想的更優雅的解決方案,但它會工作而且簡單。您可以搜索數組並將所需的translation
從一個編碼返回到另一個編碼。
希望它現在有幫助,快樂的編碼!
請評論誰是downvoting的問題,所以我可以提高相同 –
我沒有倒下,但是問題是什麼? – Andreas
@Andreas我想要所有時區的「澳大利亞/達爾文」全名爲「AUS中央標準時間」的時區 –