-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathw3cfuns_code.html
67 lines (64 loc) · 3.07 KB
/
w3cfuns_code.html
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
<html>
<head>
<title>这个编辑器有问题啊,funs们</title>
<meta charset="utf-8"/>
</head>
<body>
<div class="djs lxftime" nowtime="4/8/2014 12:56:47.50" endtime="4/9/2014 12:00:00" col="0" lxfday="yes"></div>
<script src="http://res.suning.cn/public/v3/js/jquery.js?v=20151030012890"></script>
<SCRIPT>
lxfEndtime();
//VIP倒计时
function lxfEndtime() {
$(".lxftime").each(function () {
var lxfday = $(this).attr("lxfday"); //用来判断是否显示天数的变量
var endtime = new Date($(this).attr("endtime")).getTime(); //取结束日期(毫秒值)
var nowtime = new Date($(this).attr("nowtime")).getTime(); //今天的日期(毫秒值)服务器时间
var youtime = endtime - nowtime; //还有多久(毫秒值)
var seconds = youtime / 1000;
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
var CDay = days;
var CHour = hours % 24;
var CMinute = minutes % 60;
var CSecond = Math.floor(seconds % 60); //"%"是取余运算,可以理解为60进一后取余数,然后只要余数。
var CMSecond = Math.floor(seconds*100%100);// 计算100毫秒
if (endtime <= nowtime) {
$(this).html("已过期"); //如果结束日期小于当前日期就提示过期啦
} else {
if ($(this).attr("lxfday") == "no") {
$(this).html("VIP剩余:" + CHour + "小时" + CMinute + "分" + CSecond + "秒"+(CMSecond<10?"0"+CMSecond:CMSecond)+"毫秒"); //输出没有天数的数据
} else {
if (days == 0&&CMSecond==0) {
if ($(this).attr('col') == 0) {
$(this).css('color', '#DA1919');
$(this).attr('col', '1');
} else {
$(this).css('color', '#F5D011');
$(this).attr('col', '0');
}
}
$(this).html("VIP剩余:" + (days<10?"0"+days:days) + "天" + (CHour<10?"0"+CHour:CHour) + "小时" + (CMinute<10?"0"+CMinute:CMinute) + "分" + (CSecond<10?"0"+CSecond:CSecond) + "秒"+(CMSecond<10?"0"+CMSecond:CMSecond)+"毫秒"); //输出有天数的数据
}
//当前时间变化
$(this).attr("nowtime", zhtime(nowtime+100));
}
});
setTimeout("lxfEndtime()", 100);
}
//js时间戳格式转05/20/2014 20:54:40
function zhtime(needtime) {
var oks = new Date(needtime);
var year = oks.getFullYear();
var month = oks.getMonth() + 1;
var date = oks.getDate();
var hour = oks.getHours();
var minute = oks.getMinutes();
var second = oks.getSeconds();
var msecond=oks.getMilliseconds()
return month + '/' + date + '/' + year + ' ' + hour + ':' + minute + ':' + second+'.'+msecond;
}
</SCRIPT>
</body>
</html>