-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtime.js
84 lines (67 loc) · 1.89 KB
/
time.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
var pluszero = function(d){
if(d<10)
{
d = "0"+d;
}
return d;
};
var gId = function(id){
return document.getElementById(id);
};
var GetRTime = function(iTime){
var StartTime = new Date('2016/05/01 00:00:00');
var EndTime = new Date('2016/06/01 00:00:00');
var t = EndTime.getTime() - iTime;
var d=0;
var h=0;
var m=0;
var s=0;
// 活动未开始
if(StartTime.getTime() > iTime)
{
$('.ds_limit_time').html('<strong style="font-size:40px; color:#d4172d;">活动未开始</strong>').css({"background-color":"#fdd000"});
//活动未开始
return false;
}
if(iTime > EndTime.getTime()) {
$('.ds_limit_time').html('<strong style="font-size:40px; color:#d4172d;">活动已结束</strong>').css({"background-color":"#fdd000"});
//活动已结束
return false;
}
//$('.ds_limit_time').css('padding-top',0);
var setTime = function(){
d=Math.floor(t/1000/60/60/24);
h=Math.floor(t/1000/60/60%24);
m=Math.floor(t/1000/60%60);
s=Math.floor(t/1000%60);
gId("t_d").innerHTML = pluszero(d);
gId("t_h").innerHTML = pluszero(h);
gId("t_m").innerHTML = pluszero(m);
gId("t_s").innerHTML = pluszero(s);
};
if(t>=0){
setTime();
}
var iSpaceTime = 1000;
var timer = setInterval(function(){
if(iTime<=0){
clearInterval(timer);
}
else
{
iTime+=iSpaceTime;
t = EndTime.getTime() - iTime;
setTime();
}
},iSpaceTime);
};
$.ajax({
"url":baseUrl + "/Home/Api/getTimestamp?callback=?",
"type":"get",
"dataType":"jsonp",
"success":function(d){
//console.log(d.timestamp*1000);
//console.log(+new Date);
GetRTime(d.timestamp*1000);
}
});