Php displays wrong time
I have a php script that collects data with the current timestamp.
The timestamp in the mysql database is correct (giving the correct time and date), although on the front end it displays : in 5 hours
The script that generates this output looks like this:
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));
}
}
How can I get that to show me the correct ti开发者_JAVA百科me?
I have no idea what the problem is, maybe timezone settings. Check them in your PHP.ini and in your code
精彩评论