只需将偏移量转换为秒数并将其传递给
timezone_name_from_abbr:
<?php$offset = '-7:00';// Calculate seconds from offsetlist($hours, $minutes) = explode(':', $offset);$seconds = $hours * 60 * 60 + $minutes * 60;// Get timezone name from seconds$tz = timezone_name_from_abbr('', $seconds, 1);// Workaround for bug #44780if($tz === false) $tz = timezone_name_from_abbr('', $seconds, 0);// Set timezonedate_default_timezone_set($tz);echo $tz . ': ' . date('r');演示版
第三个参数
timezone_name_from_abbr控制是否调整夏令时。
错误#44780:
timezone_name_from_abbr()在某些时区偏移量上将返回false。特别是-夏威夷,与格林尼治标准时间偏移为-10,-36000秒。



