js显示实时时间,兼容谷歌火狐浏览器
2012-03-10 09:31
447 查看
在页面加载时运行showtime();
======================================================================================
var timerID = null function MakeArray(size) { this.length = size; for (var i = 1; i <= size; i++) { this[i] = ""; } return this; } function showtime() { var userAgent = navigator.userAgent.toLowerCase(); //判断是否为google的浏览器 var chrome = /chrome/.test(userAgent); var now = new Date(); var year = now.getYear(); if ($.browser.mozilla || chrome) { year += 1900; } var month = now.getMonth() + 1; var date = now.getDate(); var hours = now.getHours(); var minutes = now.getMinutes(); var seconds = now.getSeconds(); var day = now.getDay(); Day = new MakeArray(7); Day[0] = "星期天"; Day[1] = "星期一"; Day[2] = "星期二"; Day[3] = "星期三"; Day[4] = "星期四"; Day[5] = "星期五"; Day[6] = "星期六"; var timeValue = ""; timeValue += year + "年" + " "; timeValue += ((month < 10) ? "0" : "") + month + "月" + " "; timeValue += date + "日 " + " "; timeValue += (Day[day]) + " "; timeValue += ((hours <= 12) ? hours : hours - 12); timeValue += ((minutes < 10) ? ":0" : ":") + minutes; timeValue += ((seconds < 10) ? ":0" : ":") + seconds; timeValue += (hours < 12) ? " " + "上午" : " " + "下午"; timerID = setTimeout("showtime()", 1000); var t = $("#timeValue"); t.html(timeValue); }
相关文章推荐
- 脚本标签、js显示实时时间,兼容谷歌与火狐
- JS实时显示当前时间(IE+firefox)浏览器兼容代码(图证)
- JS实时显示当前时间(IE+firefox)浏览器兼容代码(图证)
- js实时时间显示,兼容IE、Opera、Firefox,javascript面向对象编程。
- [js动态报表][兼容IE6+/火狐/360/谷歌/等各大浏览器][可手动设置间隔时间读取数据/并且显示在图表上]
- js实时获取并显示当前时间的方法
- js实时显示系统时间
- js显示实时时间[样式:年/月/日 上下午 时:分:秒 星期几](仅需一行代码)
- JS收集:实时显示系统时间
- JS中使用Date对象实时显示系统时间小示例
- JS实时时间显示
- js实时获取并显示当前时间的方法
- js动态显示实时时间
- JS 实时显示系统当前时间
- js页面实时显示时间
- js(jquery)代码在页面上实时地显示时间
- ASP+JS获取并实时显示服务器时间的代码
- JS实时显示时间
- 兼容所有浏览器的JS动态显示当前日期时间
- js下调用动态显示当前时间(兼容ie和火狐)