有人告诉我,下面这种计算用户本地时间的方法有时不起作用。在 PHP 中执行此操作的最佳方法是什么?你是做什么的?
public function getTimeOffset ($time) {
$this->_cacheTimeOffset();
if ($this->timeOffsetExecuted) {
$d = date("O");
$neg = 1;
if (substr($d, 0, 1) == "-") {
$neg = -1;
$d = substr($d, 1);
}
$h = substr($d, 0, 2)*3600;
$m = substr($d, 2)*60;
return $time + ($neg * ($h + $m) * -1) + (($this->timeOffset + $this->getDstInUse()) * 3600);
}
return $time;
}
最佳答案
使用日期时间扩展,例如DateTime::getOffset ,
或 DateTimeZone::getOffset
一些国家可能已经执行了多个时区更新,
这个方法DateTimeZone::getTransitions揭示过渡历史
关于php - 你如何处理 PHP 中的时差计算?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4299183/