php time()を使用してユーザーの現地時間を取得するにはどうすればよいですか、それとも別の方法がありますか? これはタイムゾーンにあることを意味します。time()のタイムゾーンが異なる
私は、ユーザーのローカル時間で前の時間を計算する必要が、ここに私は時間前に機能が見つかり素敵なスクリプトです:上記のスクリプトから
<?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
ユーザーのタイムゾーンはどのくらいですか?あなたのPHPスクリプトを知らない限り、それはサーバの時間がかかる( '$ time = time();')か、GMT/UTC時間を選択する( '$ time =(int)gmdate 'U'); ')。 – hakre
ありがとうManseUK – sm21guy