我会试着解释一下这里的问题.
根据PHP手册中支持的时区列表,我可以在PHP中看到所有有效的TZ标识符.
我的第一个问题是如何从代码中获取该列表,但这不是我真正需要的.
我的最终目标是编写函数isValidTimezoneId()
,如果时区有效则返回TRUE,否则返回FALSE.
function isValidTimezoneId($timezoneId) {
# ...function body...
return ?; # TRUE or FALSE
}
Run Code Online (Sandbox Code Playgroud)
所以,当我$timezoneId
在函数中使用(字符串)传递TZ标识符时我需要布尔结果.
那么,到目前为止我...
我得到的第一个解决方案是这样的:
function isValidTimezoneId($timezoneId) {
$savedZone = date_default_timezone_get(); # save current zone
$res = $savedZone == $timezoneId; # it's TRUE if param matches current zone
if (!$res) { # 0r...
@date_default_timezone_set($timezoneId); # try to set new timezone
$res = date_default_timezone_get() == $timezoneId; # it's true if new timezone set matches param …
Run Code Online (Sandbox Code Playgroud)