var time = new Date();
var year = time.getFullYear();
var mounth = time.getMonth() + 1;
var day = time.getDate();
var week = time.getDay();
var hours = time.getHours();
var minutes = time.getMinutes();
var seconds = time.getSeconds();
var milliseconds = time.getMilliseconds();
var shijiancuo = time.getTime();
//$(".j-search-data").val(year + "-" + mounth + "-" + day + " " + hours + ":" + minutes + ":" + seconds);
function countTime() {
var date = new Date();
var nowTime = date.getTime();
var endDate = new Date("2019-4-17 14:12:20");//设置截止时间
var end = endDate.getTime();
var leftTime = end - nowTime; //时间差
var d, h, m, s, ms;
d = Math.floor(leftTime / 1000 / 60 / 60 / 24);
h = Math.floor(leftTime / 1000 / 60 / 60);
m = Math.floor(leftTime / 1000 / 60 % 60);
s = Math.floor(leftTime / 1000 % 60);
ms = Math.floor(leftTime % 1000);
if(leftTime >= 0) {
if(ms < 100) { ms = "0" + ms;}
if(s < 10) { s = "0" + s;}
if(m < 10) { m = "0" + m;}
if(h < 10) { h = "0" + h;}
} else {
$(".j-search-data-button").css("color","red")
$(".j-search-data").val("0天" + "0时" + "0分" + "0秒" + " : " + " 活动已截止")
return;
}
//将倒计时赋值到div中
$(".j-search-data").val(d + "天"+h + "时"+m + "分"+s + "秒")
//递归每秒调用countTime方法,显示动态时间效果
setTimeout(countTime, 50);
}
countTime();

网友评论