How to check is timezone identifier valid from code?

后端 未结 8 1830
无人及你
无人及你 2020-12-05 04:53

I\'ll try to explain what\'s the problem here.

According to list of supported timezones from PHP manual, I can see all valid TZ identifiers in PHP.

My first

8条回答
  •  遥遥无期
    2020-12-05 05:16

    In case of php<5.3, how about this?

    public static function is_valid_timezone($timezone)
    {
        $now_timezone = @date_default_timezone_get();
    
        $result = @date_default_timezone_set($timezone);
    
        if( $now_timezone ){    
            // set back to current timezone
            date_default_timezone_set($now_timezone);
        }
    
        return $result;
    }
    

提交回复
热议问题