DQE
2016-09-25 15:09
getDay是不是只有0到6啊>?
恩
<!doctype html> <html> <head> <meta charset="utf-8"> <title>时间显示</title> <script> window.onload=function(){ showTime(); } function checkTime(i){ if(i<10){ i="0"+i; }return i; } function showTime(){ var myDate=new Date(); var year=myDate.getFullYear(); var month=myDate.getMonth()+1; var day=myDate.getDate(); var d=myDate.getDay(); var h=myDate.getHours(); var m=myDate.getMinutes(); var s=myDate.getSeconds(); m=checkTime(m); s=checkTime(s); var weekday=new Array(7); weekday[0]="星期日"; weekday[1]="星期一"; weekday[2]="星期二"; weekday[3]="星期三"; weekday[4]="星期四"; weekday[5]="星期五"; weekday[6]="星期六"; document.getElementById("show").innerHTML=year+"年"+month+"月"+day+"日"+weekday[d]+h+":"+m+":"+s; setTimeout(showTime,500); } </script> </head> <body> <div id="show"> 显示时间 </div> </body> </html>
为什么月要+1
var
month
=
myDate
.getMonth()+1;
是的啊
JavaScript进阶篇
468061 学习 · 21891 问题
相似问题