我需要一个完全相反的timezone_name_from_abbr()方法:http://php.net/manual/en/function.timezone-name-from-abbr.php
我有一个时区名称列表如下:
Australia/Brisbane
Australia/Hobart
Asia/Vladivostok
Australia/Lord_Howe
Asia/Magadan
Asia/Kolkata
America/Los_Angeles
......
Run Code Online (Sandbox Code Playgroud)
我需要一个方法,它将时区作为一个参数,并返回一个它的缩写.例如:
如果我使用如下方法:
$timeAbbr = timezone_abbr_from_name('America/Los_Angeles');
echo $timeAbbr;
Run Code Online (Sandbox Code Playgroud)
结果应该是:
PST
Run Code Online (Sandbox Code Playgroud)
这应该工作.
function timezone_abbr_from_name($timezone_name){
$dateTime = new DateTime();
$dateTime->setTimeZone(new DateTimeZone($timezone_name));
return $dateTime->format('T');
}
Run Code Online (Sandbox Code Playgroud)