私はjQueryカウントダウンを使用しています: http://keith-wood.name/countdown.html
このスクリプトの使用例は次のとおりです。
$(selector).countdown({since: new Date(2010, 12-1, 25)});
完全な日付を設定する必要があります。合計時間が秒単位しかない場合はどうなりますか? つまり、50000 秒からカウントダウンを設定し、自動的に日:時間:秒に変換したいということですか?
私はjQueryカウントダウンを使用しています: http://keith-wood.name/countdown.html
このスクリプトの使用例は次のとおりです。
$(selector).countdown({since: new Date(2010, 12-1, 25)});
完全な日付を設定する必要があります。合計時間が秒単位しかない場合はどうなりますか? つまり、50000 秒からカウントダウンを設定し、自動的に日:時間:秒に変換したいということですか?
さらに制御したい場合に備えて、カウンターを実行する小さな関数を作成しました。
countDown($('#selector'), 300);
function countDown(selector, seconds){
var oneSecond = 1;
var passedSeconds = 0;
var timeLeft = 0;
var interval = setInterval(
function(){
passedSeconds += oneSecond;
timeLeft = seconds-passedSeconds;
if(timeLeft > 0 ){
selector.text(getTimer(timeLeft));
}else{
selector.text('Time out');
clearInterval(interval);
}
},
oneSecond*1000);
}
function getTimer(timeLeft){
var litteralDuration = '';
var s = parseInt(timeLeft);
var d = Math.floor(s / 86400);
s %= 86400;
var h = Math.floor(s / 3600);
s %= 3600;
var m = Math.floor(s / 60);
s %= 60;
if(d > 0){
litteralDuration += (d == 1) ? '1 D ' : d + ' Ds ' ;
}
if(h > 0){
litteralDuration += (h == 1) ? '1 H ' : h + ' Hs ' ;
}
if(m > 0){
litteralDuration += (m == 1) ? '1 M ' : m + ' Ms ' ;
}
if(s > 0){
litteralDuration += (s == 1) ? '1 S ' : s + ' Ss ' ;
}
return litteralDuration;
}
これが JS Fiddle です: Fiddle
それが役立つことを願っています