【发布时间】:2012-03-20 13:56:37
【问题描述】:
我需要将时间戳转换为 UTC-5
$offset 是用户的时区,值从 -12 到 12。$ds 是夏令时,如果开启,它将增加一个小时。我制作了这个函数,但我认为它会将 UTC-5 时间戳转换为基于用户时区的新时间戳……我需要反转该函数,以便它返回 UTC-5 中的时间戳。当然,问题远不止于此,但这就是我卡住的地方。有什么办法吗?
function input_date($timestamp)
{
global $vbulletin;
$timestamp = (int)$timestamp;
if (strlen((string)$timestamp) == 10)
{
$hour = 3600.00;
$offset = $vbulletin->userinfo['timezoneoffset'];//sample -8
$ds = (int)$vbulletin->userinfo['dstonoff'];//DST values are 1 or 0
$fluff = $hour*($offset+5.00);
$timestamp = $timestamp+$fluff+($ds*$hour);
return $timestamp;//return timestamp in UTC-5 format..
}
else
{
return 0;
}
}
【问题讨论】:
-
您是否可以选择使用 时区标识符 而不是偏移量 + DST 标志?时区标识符是指
Asia/Tokyo或Europe/London之类的名称。然后,您可以轻松地为此使用现有的 PHP 函数,而不是重新发明时间计算,这总是容易出错。