你所要求的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中央标准时间”的时区 –