日期:2014-05-16 浏览次数:20772 次
<div>
<div id = "date"></div>
<div id = "day"></div>
<div id = "time"></div>
? ?<div id = "timestr"></div>
</div>
function setDMY()
{
var dateOb =new Date();
var d = checklen(dateOb.getMonth() + 1)+"."+checklen(dateOb.getDate())+"
."+dateOb.getFullYear().toString();
document.getElementById("date").innerHTML = d;
var d2 = getCHday(dateOb.getDay() + 1);
document.getElementById("day").innerHTML = d2;
var obj = get12Hours(dateOb.getHours());
var time = checklen(obj.h) + ":" + checklen(dateOb.getMinutes()) +":" +
checklen(dateOb.getSeconds());
document.getElementById("time").innerHTML = time;
document.getElementById("timestr").innerHTML = obj.str;
setTimeout("setDMY()",1000);
}
function checklen(da)
{
if(da.toString().length == 1)
return "0" + da.toString();
else
return da.toString();
}
function getCHday(day)
{
switch(day)
{
case 1:return "星期一";
case 2:return "星期二";
case 3:return "星期三";
case 4:return "星期四";
case 5:return "星期五";
case 6:return "星期六";
case 7:return "星期日";
}
}
function get12Hours(hours){
var obj = new Object();
if(hours > 12)
{
obj.h = hours - 12;
obj.str = "pm";
}
else
{
obj.h = hours;
obj.str = "am";
}
return obj;
}
setDMY();
<div>
<div id = "date"></div>
&