您應該使用時間戳比較。
JS:
var timestamp = (new Date()).getTime(); // send this to your php
PHP:
$timestampFromJs = intval($_GET["ts"]); // just made it up
$ts = time() * 1000; // js timestamp is milliseconds
if($ts - $timestampFromJs > 5000*60) ...
更新:如果您需要時區安全比較:
JS:
var timestamp = (new Date()).getTime();
PHP:
$timestampFromJs = intval($_GET["ts"]); // just made it up
$date_utc = new \DateTime("now", new \DateTimeZone("UTC"));
$ts = $date_utc->getTimestamp() * 1000; // js timestamp is milliseconds
if($ts - $timestampFromJs > 5000*60) ...
您應該改用unix時間戳。 –
時間對比較重要嗎? –
我也有日期時間戳帶JavaScript中的區域以毫秒爲單位這樣.....「1494688862301」.....所以我怎麼能比較這個在PHP? –