timezone_name_from_abbr() sometimes returns FALSE instead of an actual timezone: http://bugs.php.net/44780
It's possible to workaround it for some cases by getting the timezone name from timezone_abbreviations_list(). For example, if you have the GMT offset and want a timezone name:
<?php
/* Takes a GMT offset (in hours) and returns a timezone name */
function tz_offset_to_name($offset)
{
$offset *= 3600; // convert hour offset to seconds
$abbrarray = timezone_abbreviations_list();
foreach ($abbrarray as $abbr)
{
foreach ($abbr as $city)
{
if ($city['offset'] == $offset)
{
return $city['timezone_id'];
}
}
}
return FALSE;
}
?>
timezone_name_from_abbr
(PHP 5 >= 5.1.3)
timezone_name_from_abbr — 略称からタイムゾーン名を返す
説明
string timezone_name_from_abbr
( string $abbr
[, int $gmtOffset
[, int $isdst
]] )
パラメータ
- abbr
-
タイムゾーンの略称。
- gmtOffset
-
GMT からのオフセット秒数。デフォルトは -1 で、 この場合は abbr に対応するタイムゾーンのうち最初に見つかったものを返します。 それ以外の場合は指定したオフセットを探し、 そこで見つからなかった場合には 他のオフセットも含めて最初に見つかったものを返します。
- isdst
-
夏時間の識別子。abbr が存在しなかった場合は、 offset と isdst をもとにタイムゾーンを探します。
返り値
成功した場合にタイムゾーン名、失敗した場合に FALSE を返します。
例
例1 timezone_name_from_abbr() の例
<?php
echo timezone_name_from_abbr("CET") . "\n";
echo timezone_name_from_abbr("", 3600, 0) . "\n";
?>
上の例の出力は、たとえば 以下のようになります。
Europe/Berlin Europe/Paris
timezone_name_from_abbr
chris at mretc dot net
11-Nov-2008 02:25
11-Nov-2008 02:25
