<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script type="text/javascript">
function downTime(date) {
var arr = date.split(/[- :]/);
date = new Date(arr[0], arr[1] - 1, arr[2], arr[3], arr[4], arr[5]);
var t = date.getTime() - Date.now();
if (t > 0) {
var seconds = Math.floor((t / 1000) % 60);
var minutes = Math.floor((t / 1000 / 60) % 60);
var hours = Math.floor((t / (1000 * 60 * 60)) % 24);
var days = Math.floor(t / (1000 * 60 * 60 * 24));
console.log (days > 0 ? days + '天' : '' + hours + '时' + minutes + '分' + seconds + '秒');
} else {
console.log( '所设时间小于当前时间');
}
}
var timer=setInterval(function(){
downTime('2016-06-29 13:08:13')
},1000)
// 调用的时候使用setInterval定时器每1000毫秒运行一次即可
</script>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script type="text/javascript">
function downTime(date) {
var arr = date.split(/[- :]/);
date = new Date(arr[0], arr[1] - 1, arr[2], arr[3], arr[4], arr[5]);
var t = date.getTime() - Date.now();
if (t > 0) {
var seconds = Math.floor((t / 1000) % 60);
var minutes = Math.floor((t / 1000 / 60) % 60);
var hours = Math.floor((t / (1000 * 60 * 60)) % 24);
var days = Math.floor(t / (1000 * 60 * 60 * 24));
console.log (days > 0 ? days + '天' : '' + hours + '时' + minutes + '分' + seconds + '秒');
} else {
console.log( '所设时间小于当前时间');
}
}
var timer=setInterval(function(){
downTime('2016-06-29 13:08:13')
},1000)
// 调用的时候使用setInterval定时器每1000毫秒运行一次即可
</script>
</body>
</html>