我怎样才能获得用户的本地时间使用PHP的时间()或有另一种方式来做到这一点? 这意味着它将在他们的时区。时间()与不同的时区
我需要与用户的本地时间前计算的时候,这里是一个不错的剧本,我发现了以前的时间功能:
<?php
function timeago($time)
{
$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
$lengths = array("60","60","24","7","4.35","12","10");
$now = time();
$difference = $now - $time;
$tense = "ago";
for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++)
{
$difference /= $lengths[$j];
}
$difference = round($difference);
if($difference != 1)
{
$periods[$j].= "s";
}
return "$difference $periods[$j] $tense";
}
?>
<?php
$date = strtotime('2012-04-15 07:41:03');
$datep = timeago($date);
echo $datep;
?>
从上面的脚本中,我使用的时间(),但它只是得到我的服务器时间不是当地时间在我身边。我如何获得当地时间(用户当地时间)?
重复http://stackoverflow.com/questions/4746249/get-user-timezone或http://stackoverflow.com/questions/13/how-can-i-determine-a-web-users-time-zone ?? – ManseUK 2012-04-17 09:24:54
什么是用户时区?除非你不告诉你的PHP脚本,否则它不知道它需要服务器时间('$ time = time();'),或者你选择GMT/UTC时间('$ time =(int)gmdate 'U');')。 – hakre 2012-04-17 09:26:35
谢谢ManseUK – sm21guy 2012-04-17 09:28:55