|
<html>
<head>
<title>时间输出</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
function disptime() {
var now = new Date(); //创建一个表示当前日期和时间的对象NOW
var year = now.getYear(); //不行使用这个方法 :now.getFullYear()
var month = now.getMonth() + 1;
var date = now.getDate();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
if (month >= 10) { month = month; }
else { month = "0" + month; }
if (date >= 10) { date = date; }
else { date = "0" + date; }
if (hours >= 10) { hours = hours; }
else { hours = "0" + hours; }
if (minutes >= 10) { minutes = minutes; }
else { minutes = "0" + minutes; }
if (seconds >= 10) { seconds = seconds; }
else {seconds = "0" + seconds;}
document.getElementById("timeShow").innerHTML = year + "-" + month + "-" + date + " " + hours + ":" + minutes + ":" + seconds + " ";
setTimeout("disptime ()", 1000)
}
</script>
</head>
<body onload="disptime()">
<form id="form1" runat="server">
<div>
<span id="timeShow">时间</span>
</div>
</form>
</body>
</html>
本文由胡金金个人网站整理发布,转载请注明地址:http://www.hujinjin.com/info/374.html