JS获取当前时间戳的方法
JavaScript 获取当前时间戳:
第一种方法:
var time =Date.parse(new Date());
结果:1463732230000
第二种方法:
var time =(new Date()).valueOf();
结果:1463732231455
第三种方法:
var time=new Date().getTime();
结果:1463732299085
var ems = document.getElementsByTagName("em");
var t_time = "2016/05/20 20:00:00";
s_time = new Date(t_time);
s_time = Date.parse(t_time) / 1000;
(function setTime(){
var n_time = Date.parse(new Date()) /1000;
var time = s_time-n_time;
if (time>0) {
var d = parseInt(time / 86400);
time = time - d * 86400;
var h = parseInt(time / 3600);
time = time - h * 3600;
var m = parseInt(time / 60);
time = time - m * 60;
var s = time;
ems[3].innerHTML = s;
ems[2].innerHTML = m;
ems[1].innerHTML = h;
ems[0].innerHTML = d;
setTimeout(setTime, 500);
}else {
alert('倒计时结束了')
}
})();