我有一个php脚本,用当前时间戳收集数据。
mysql数据库中的时间戳是正确的(给出正确的时间和日期),虽然在前端显示:在5小时内
生成此输出的脚本如下所示:
function plural($num) {
if ($num != 1)
return "s";
}
function relative_date($date) {
$diff = time() - strtotime($date);
if ($diff>0) {
if ($diff<60)
return $diff . " second" . plural($diff) . " ago";
$diff = round($diff/60);
if ($diff<60)
return $diff . " minute" . plural($diff) . " ago";
$diff = round($diff/60);
if ($diff<24)
return $diff . " hour" . plural($diff) . " ago";
$diff = round($diff/24);
if ($diff<7)
return $diff . " day" . plural($diff) . " ago";
$diff = round($diff/7);
if ($diff<4)
return $diff . " week" . plural($diff) . " ago";
return date("M j, Y", strtotime($date));
} else {
if ($diff>-120)
return "Right now";
if ($diff>-60)
return "in " . -$diff . " second" . plural($diff);
$diff = round($diff/60);
if ($diff>-60)
return "in " . -$diff . " minute" . plural($diff);
$diff = round($diff/60);
if ($diff>-24)
return "in " . -$diff . " hour" . plural($diff);
$diff = round($diff/24);
if ($diff>-7)
return "in " . -$diff . " day" . plural($diff);
$diff = round($diff/7);
if ($diff>-4)
return "in " . -$diff . " week" . plural($diff);
return date("M j, Y", strtotime($date));
}
}
我怎样才能告诉我正确的时间?
答案 0 :(得分:2)
我不知道问题是什么,也许是时区设置。在PHP.ini和代码中检查它们