js实时显示系统时间
2010-05-14 15:45
337 查看
刚刚在做后台页面最上面要动态显示时间刚写了这个代码
将这段代码加入<head></head>
<!--时间显示代码 -->
<script>
function clockon(contentDate){
var now = new Date();
var year = now.getYear();
var month = now.getMonth();
var date = now.getDate();
var day = now.getDay();
var hour = now.getHours();
var minu = now.getMinutes();
var sec = now.getSeconds();
var week;
month = month+1;
if(month<10)month="0"+month;
if(date<10)date="0"+date;
if(hour<10)hour="0"+hour;
if(minu<10)minu="0"+minu;
if(sec<10)sec="0"+sec;
//var arr_week = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
//week = arr_week[day]; 这里显示星期几,我不用所以注释掉了
var time = "";
time = year+"-"+month+"-"+date+" "+hour+":"+minu+":"+sec;
//time = year+"-"+month+"-"+date+"week"+hour+":"+minu+":"+sec; 如果需要显示周几的话可以用这句代码
if(document.all){
contentDate.innerHTML=""+time+"" }
var timer = setTimeout("clockon(contentDate)",200);
}</script>
<!--时间显示代码 -->
需要显示时间的地方代码如下:<div align="right" id="contentDate" ></div>
将这段代码加入<head></head>
<!--时间显示代码 -->
<script>
function clockon(contentDate){
var now = new Date();
var year = now.getYear();
var month = now.getMonth();
var date = now.getDate();
var day = now.getDay();
var hour = now.getHours();
var minu = now.getMinutes();
var sec = now.getSeconds();
var week;
month = month+1;
if(month<10)month="0"+month;
if(date<10)date="0"+date;
if(hour<10)hour="0"+hour;
if(minu<10)minu="0"+minu;
if(sec<10)sec="0"+sec;
//var arr_week = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
//week = arr_week[day]; 这里显示星期几,我不用所以注释掉了
var time = "";
time = year+"-"+month+"-"+date+" "+hour+":"+minu+":"+sec;
//time = year+"-"+month+"-"+date+"week"+hour+":"+minu+":"+sec; 如果需要显示周几的话可以用这句代码
if(document.all){
contentDate.innerHTML=""+time+"" }
var timer = setTimeout("clockon(contentDate)",200);
}</script>
<!--时间显示代码 -->
需要显示时间的地方代码如下:<div align="right" id="contentDate" ></div>
相关文章推荐
- js 显示系统时间yyyy-MM-dd HH:mm:ss,实时
- JS使用Date对象实时显示当前系统时间简单示例
- JS中使用Date对象实时显示系统时间小示例
- HTML+JS获取系统实时时间并显示
- js实时显示系统时间
- JS收集:实时显示系统时间
- 实时显示系统时间(JS)
- JS 实时显示系统当前时间
- JS实时显示系统时间
- 用JS实现实时显示系统时间
- 转载:JS实时显示系统时间
- 使用js显示当前系统时间
- Qt 实现实时系统时间显示
- 实时显示系统时间
- 使用js实时显示北京时间
- 脚本标签、js显示实时时间,兼容谷歌与火狐
- 实时显示时间(HTML+JS)
- QT显示实时系统时间
- Android笔记:Android TextView实时显示系统时间
- 利用Handler通信来实时显示系统时间