今天一项目客户需要在网站上显示当前日期及时间还有星期时间,jquery的实时更新显示正好用到了.以下是jquey实时显示时间的全部代码,记录以备用.
<script src=\"js/jquery.min.js\" type=\"text/javascript\"></script>
<script type=\"text/javascript\">
$(function() {
setInterval(\"GetTime()\", 1000);
});
function GetTime() {
var mon, day, now, hour, min, ampm, time, str, tz, end, beg, sec;
/*
mon = new Array(\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\",
\"Sep\", \"Oct\", \"Nov\", \"Dec\");
*/
mon = new Array(\"一月\", \"二月\", \"三月\", \"四月\", \"五月\", \"六月\", \"七月\", \"八月\",
\"九月\", \"十月\", \"十一月\", \"十二月\");
/*
day = new Array(\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\");
*/
day = new Array(\"周日\", \"周一\", \"周二\", \"周三\", \"周四\", \"周五\", \"周六\");
now = new Date();
hour = now.getHours();
min = now.getMinutes();
sec = now.getSeconds();
if (hour < 10) {
hour = \"0\" + hour;
}
if (min < 10) {
min = \"0\" + min;
}
if (sec < 10) {
sec = \"0\" + sec;
}
$(\"#Timer\").html(
\"<nobr>\" + day[now.getDay()] + \", \" + mon[now.getMonth()] + \" \"
+ now.getDate() + \", \" + now.getFullYear() + \" \" + hour
+ \":\" + min + \":\" + sec + \"</nobr>\");
}
</script>