js时钟&倒计时

<!DOCTYPE HTML>

<html>
<head>
<meta charset=UTF-8>
<title>recursion</title>
<style type="text/css">
</style>
<script type="text/javascript">
onload = function ()
{
setTimeout (function ()
{
var date = new Date();
var year = date.getFullYear();
date.setHours (date.getHours () + 1);
var m = date.getMonth () + 1;
m = m < 10 ? "0" + m : m;
var d = date.getDate ();
d = d < 10 ? "0" + d : d;
var h = date.getHours ();
h = h < 10 ? "0" + h : h;
var mm = date.getMinutes ();
mm = mm < 10 ? "0" + mm : mm;
var ss = date.getSeconds();
ss = ss < 10 ? "0" + ss : ss;
txt.value = year + "-" + m + "-" + d + " " + h + ":" + mm + ":" + ss;
}, 1000);

}

function shizhong(enddatestring) {
var date = new Date();
var year = date.getFullYear();
date.setHours(date.getHours() + 1);
var m = date.getMonth() + 1;
m = m < 10 ? "0" + m : m;
var d = date.getDate();
d = d < 10 ? "0" + d : d;
var h = date.getHours();
h = h < 10 ? "0" + h : h;
var mm = date.getMinutes();
mm = mm < 10 ? "0" + mm : mm;
var ss = date.getSeconds();
ss = ss < 10 ? "0" + ss : ss;
txt.value = year + "-" + m + "-" + d + " " + h + ":" + mm + ":" + ss;
setTimeout("shizhong('" + date + "')", 1000);
}

function dianji() {
var selectDate = new Date();
var year = selectDate.getFullYear();
selectDate.setHours(selectDate.getHours() + 1);
var m = selectDate.getMonth() + 1;
m = m < 10 ? "0" + m : m;
var d = selectDate.getDate();
d = d < 10 ? "0" + d : d;
var h = selectDate.getHours();
h = h < 10 ? "0" + h : h;
var mm = selectDate.getMinutes();
mm = mm < 10 ? "0" + mm : mm;
var ss = selectDate.getSeconds();
ss = ss < 10 ? "0" + ss : ss;
var checkDate = new Date(year + "-" + m + "-" + d + " " + h + ":" + mm + ":" + ss);

alert(checkDate);
}
</script>
<script type="text/javascript">
function countDown(secs) {
var sp1 = document.getElementById('sp1');
sp1.innerHTML = secs;
if (--secs > 0) {
setTimeout("countDown(" + secs + ")", 1000);
}
else {
sp1.innerHTML ="倒计时完成";
}
}
</script>
</head>
<body>
<div style="margin:10px;">
<input type="text" id="txt" />
<input id="btnDianJi" type="button" value="get current date" onclick="dianji();" />
</div>
<div style="margin:10px;">
<input type="text" id="txt1" value="5" style="width:50px;" />
<span id="sp1"></span>
<script type="text/javascript">
var start = document.getElementById("txt1").value;
countDown(start);
shizhong('2015-09-30 13:00:00');
</script>
</div>

</body>
</html>

上一篇:Python之旅:数据类型、字符编码、文件处理


下一篇:linux下c++實現簡單的生產者消費者隊列模式