forked from Huxpro/huxpro.github.io
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
25 lines (21 loc) · 936 Bytes
/
test.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
function fn(){
var targetDate=new Date("2018-01-01");
var indexDate=new Date();
console.log(indexDate);
var total=(targetDate-indexDate);
var days=Math.floor(total/24/60/60/1000);
var hours=indexDate.getMinutes()==0?24-indexDate.getHours():24-indexDate.getHours()-1;
var minutes=indexDate.getSeconds()==0?60-indexDate.getMinutes():60-indexDate.getMinutes()-1;
var seconed=60-indexDate.getSeconds();
return {
days:days,
hours:hours.toString().length==1?"0"+hours.toString():hours.toString(),
minutes:minutes.toString().length==1?"0"+minutes.toString():minutes.toString(),
seconed:seconed.toString().length==1?"0"+seconed.toString():seconed.toString(),
}
}
setInterval(function(){
var json=fn();
document.getElementById("days").innerText=json.days;
document.getElementById("date").innerText=json.hours+":"+json.minutes+":"+json.seconed;
},10000);