日期:2014-05-18 浏览次数:20449 次
// 本地时钟 function clockon() { var now = new Date(); var year = now.getFullYear(); // getFullYear 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("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"); week = arr_week[day]; var time = ""; time = year + "年" + month + "月" + date + "日" + " " + hour + ":" + minu + ":" + sec + " " + week; $("#bgclock").html(time); var timer = setTimeout("clockon()", 1000);
------解决方案--------------------
function display() //时间
{
var d=new Date();
var year=d.getFullYear();
var month=d.getMonth()+1;
var day=d.getDate();
var hour=d.getHours();
var minu=d.getMinutes();
var sec=d.getSeconds();
if(minu<10)
{
minu="0"+minu;
}
if(sec<10)
{
sec="0"+sec;
}
if(hour<12)
{
str="AM";
}
else
{
str="PM";
}
document.getElementById("time").value=year+"年"+month+"月"+day+"日 "+hour+":"+minu+":"+sec+" "+str;
setTimeout("display()",1000);
}
调用位置
<body onLoad="display()">
------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>无标题页</title> <script language = "javascript" > function ShowTime() { var seconds,minutes,hours,day,month,year; var timer = new Date(); if(timer.getSeconds()<10) seconds = "0"+timer.getSeconds(); else seconds = timer.getSeconds(); if(timer.getMinutes()<10) minutes = "0"+timer.getMinutes(); else minutes = timer.getMinutes(); if(timer.getHours()<10) hours = "0"+timer.getHours(); else hours = timer.getHours(); month = timer.getMonth() + 1; document .getElementById ("dateTime").innerHTML = timer.getFullYear()+"年"+month+"月"+timer.getDate ()+"日"+ hours+":"+minutes+":"+seconds; } function test() { setInterval (ShowTime ,1000); } </script&