用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>
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>
相关文章推荐
- [原创]利用php和javascript实现服务器时间电子时钟
- 五步轻松实现JavaScript HTML时钟效果
- JavaScript实现简单的时钟实例代码
- javascript背景时钟实现方法
- 用JavaScript实现超酷的“网页时钟”
- JavaScript实现简单的时钟实例代码
- Atitit. Java script 多重多重catch语句的实现and Javascript js 异常机制
- 用25行JavaScript语句实现一个简单的编译器
- JavaScript实现动态时钟,自己刚写出来的希望能给您带来帮助,逻辑有待精简,欢迎评价
- 前端模型--纯js实现简易日历&&电子时钟
- javascript实现超酷的“网页时钟
- JavaScript电子时钟倒计时
- 利用多线程实现电子时钟
- JavaScript电子时钟倒计时第二款
- JavaScript实现仿Clock ISO时钟
- JavaScript实现美女时钟
- ArcGIS.Server.9.3和ArcGIS API for JavaScript实现语句查询QueryTask(八)
- 程序员用css3实现网页电子时钟,校准北京时间
- javascript实现动态日期和实时时钟
- 实现电子时钟效果