-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
35 lines (25 loc) · 1.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function zeroPadding(num,length){
return ('0000000000' + num).slice(-length);
}
function countDown () {
const nowDate = Date.now();
const nowYear = new Date().getFullYear();
const target = new Date(`${nowYear + 1}-01-01T00:00+09:00`);
const targetDate = target.getTime();
let diffTime = targetDate - nowDate;
if( diffTime < 0 ) return $('.times').css('display','none');
const day = diffTime / ( 1000 * 60 * 60 * 24 );
diffTime = diffTime % ( 1000 * 60 * 60 * 24 );
const hour = diffTime / ( 1000 * 60 * 60 );
diffTime = diffTime % ( 1000 * 60 * 60);
const min = diffTime / ( 1000 * 60 );
diffTime = diffTime % ( 1000 * 60);
const sec = diffTime / 1000;
diffTime = diffTime % 1000;
$('#next-year').text(nowYear + 1)
$('#days').text(Math.floor(day))
$('#hours').text(zeroPadding(Math.floor(hour), 2))
$('#minutes').text(zeroPadding(Math.floor(min), 2))
$('#seconds').text(zeroPadding(Math.floor(sec), 2))
}
setInterval('countDown()', 100);