您的位置:首页 > Web前端 > JavaScript

js输出时间代码

2013-04-17 10:03 260 查看
<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>无标题文档</title>

<script type="text/javascript">

function Time()

{

var date = new Date();

var hour=date.getHours();

var min=date.getMinutes();

var sec=date.getSeconds();

var apm="AM";

if(hour>12)

{

apm="PM";

hour="0"+(hour-12);

}

if(min<10)

{min="0"+min;

}

if(sec<10)

{sec="0"+sec;

}

document.getElementById("timer").value=hour+":"+min+":"+sec+""+apm;

c=setTimeout("Time(),1000");

}

</script>

</head>

<body onload="Time()" bgcolor="#00FF00">

<center>当前系统时间为:<input type="text" id="timer" style="width:200px"/>

<input type="button" id="top" style="width:auto" value="时间停止" onclick="clearTimeout(c)" />

</center>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: