用JAVASCRIPT语句实现电子时钟

实例化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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值