2016-04-08 8 views
0

時間の計算はサーバー側で行われます。 JS/jQuery & PHP(または任意のサーバー側スクリプトまたはプログラミング言語)を使用して作成できます。サーバー側のスクリプトでは、ローカルマシンの時刻ではなくサーバーの時刻が考慮されます。地理的な場所から実行しても同じ残り時間が表示されます。サーバー側のカウントダウンスクリプト

+0

yはなかったですあなた自身の質問に答えてください。または、あなたの答えにあるコードを変更する方法、あるいはこれについては何ですか? – Andreas

答えて

0

JSコード:

<script> 
 
jQuery(document).ready(function() { 
 
    var refreshId_sec = setInterval(function() { 
 
    \t var target_url = 'show_diff.php?show=all&randval='+ Math.random();  
 
\t jQuery.ajax({url: target_url, success: function(result){ 
 
\t \t var arr_res = result.split("|"); \t \t 
 
\t \t document.getElementById('sec').innerHTML = arr_res[3]; 
 
\t \t document.getElementById('min').innerHTML = arr_res[2]; 
 
\t \t document.getElementById('hour').innerHTML = arr_res[1]; 
 
\t \t document.getElementById('day').innerHTML = arr_res[0]; 
 
    }}); 
 
    }, 1000); 
 
</script>

PHPコード:

<?php 
 

 
$then = '2016-04-08 10:00:00'; // end time here 
 
$then = new DateTime($then, new DateTimeZone('Asia/Calcutta')); 
 
$now = new DateTime(); 
 
$sinceThen = $then->diff($now); 
 
if($_GET["show"]=="all") 
 
\t echo $sinceThen->d."|".$sinceThen->h."|".$sinceThen->i."|".$sinceThen->s; 
 
?>

チェック完全なコードに:http://blog.phpcode.co.in/php/server-side-countdown-counter-script/

関連する問題