经测试代码如下:
/**
* 计算时区的时差
*
* @author 编程之家 jb51.cc jb51.cc
* @param string $remote_tz 远程时区
* @param string $origin_tz 标准时区
*
*/
function getTimeZoneOffset($remote_tz,$origin_tz = 'UTC') {
if ($origin_tz === null) {
if (!is_string($origin_tz = date_default_timezone_get())) {
return false; // A UTC timestamp was returned -- bail out!
}
}
$origin_dtz = new DateTimeZone($origin_tz);
$remote_dtz = new DateTimeZone($remote_tz);
$origin_dt = new DateTime('now',$origin_dtz);
$remote_dt = new DateTime('now',$remote_dtz);
$offset = $origin_dtz->getOffset($origin_dt) - $remote_dtz->getOffset($remote_dt);
return $offset;
}
原文链接:https://www.f2er.com/php/529181.html