<script>
var timestamp = new Date().getTime();
当前时间
var startTime = new Date(timestamp);
var endTime = new Date(timestamp + 2 * 60 * 60 * 1000);
时间戳
//var endTime=new Date(timestamp)
function TimeDown() {
//结束时间
var endDate = endTime;
//当前时间
var nowDate = new Date();
//相差的总秒数
var totalSeconds = parseInt((endDate - nowDate) / 1000);
if (totalSeconds == 0) {
alert('考试时间已到!');
totalSeconds = 0;
}
if (totalSeconds < 0) {
totalSeconds = 0;
}
//天数
var days = Math.floor(totalSeconds / (60 * 60 * 24));
//取模(余数)
var modulo = totalSeconds % (60 * 60 * 24);
//小时数
var hours = Math.floor(modulo / (60 * 60));
modulo = modulo % (60 * 60);
//分钟
var minutes = Math.floor(modulo / 60);
//秒
var seconds = modulo % 60;
//输出到页面
$('#menu1-').html(hours + ":" + minutes + ":" + seconds);
//延迟一秒执行自己
setTimeout(function () {
TimeDown();
}, 1000)
}
TimeDown();
</script>