标签:
时钟效果一:
代码:
<html> <head> <meta charset="utf-8"/> <title>JavaScript日期时间对象的创建与使用</title> </head> <body> <h2 id="time"></h2> <script type="text/javascript"> function Clock(){ var time = new Date(); var y = time.getFullYear(); // 年份 var m = time.getMonth() + 1; // 月份 var d = time.getDate(); // 天 var w = time.getDay(); // 星期 switch(w){ case 1: w = ‘星期一‘; break; case 2: w = ‘星期二‘; break; case 3: w = ‘星期三‘; break; case 4: w = ‘星期四‘; break; case 5: w = ‘星期五‘; break; case 6: w = ‘星期六‘; break; case 0: w = ‘星期日‘; break; } var hh = time.getHours(); // 小时 var mm = time.getMinutes(); // 分钟 var ss = time.getSeconds(); // 秒数 var now = y + ‘-‘ + m + ‘-‘ + d + ‘ ‘ + hh + ‘:‘ + mm + ‘:‘ + ss + ‘ ‘ + w; document.getElementById(‘time‘).innerHTML = now; } // 自动跳动 setInterval(Clock,1000); </script> </body> </html>
时钟效果二:
效果:
代码地址:http://git.oschina.net/mpf/KOPMJS/tree/master/Clock/
标签:
原文地址:http://my.oschina.net/mpf/blog/529674