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

用JAVASCRIPT语句实现电子时钟

2005-05-26 17:41 597 查看
实例化date类
today = new Date();
分别取时、分、秒的数值
intHours = today.getHours();
intMinutes = today.getMinutes();
intSeconds = today.getSeconds();
格式化待输出的样式
if (intHours == 0) {
hours = "12:";
xfile = "午夜 ";
} else if (intHours < 12) {
hours = intHours+":";
xfile = "上午 ";
} else if (intHours == 12) {
hours = "12:";
xfile = "正午 ";
} else {
intHours = intHours - 12
hours = intHours + ":";
xfile = "下午 ";
}
if (intMinutes < 10) {
minutes = "0"+intMinutes+":";
} else {
minutes = intMinutes+":";
}
if (intSeconds < 10) {
seconds = "0"+intSeconds+" ";
} else {
seconds = intSeconds+" ";
}
timeString = xfile+hours+minutes+seconds;
定位到文档中输出
document.all.Clock.innerHTML = timeString;
显示间隔
window.setTimeout("tick();", 100);
装载:
<body onLoad="tick()">
设此DIV的ID值为CLOCK,则在JAVASCRIT定义的输出即会在此显示
<div id="Clock" style="position:relative;top:-2px;"></div>
</body>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: