Skip to content

Instantly share code, notes, and snippets.

@sugarshin
Created February 3, 2014 14:07
Show Gist options
  • Save sugarshin/8784432 to your computer and use it in GitHub Desktop.
Save sugarshin/8784432 to your computer and use it in GitHub Desktop.
カウントダウンタイマー
$(function() {
countDown();
});
function countDown() {
var startTime = new Date(),
endTime = new Date('March 9,2014, 00:00:00'),
diff = endTime - startTime,
times = 24 * 60 * 60 * 1000,
day = Math.floor(diff / times),
hour = Math.floor(diff % times / (60 * 60 * 1000)),
min = Math.floor(diff % times / (60 * 1000)) % 60,
sec = Math.floor(diff % times / 1000) % 60 % 60;
// var ms = Math.floor(diff % times / 10) % 100
if (diff > 0) {
$('#h').text(day + '日' + hour + '時間' + min + '分' + sec +'秒');
setTimeout('countDown()', 1000);
} else {
// 処理
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment