麟角
2016-03-13 20:24
var date = new Date;
var year = date.getFullYear();
var mon = date.getMonth()+1;
var day = date.getDate();
var weekday = new Array(7);
weekday = ["星期一","星期二","星期三","星期四","星期五","星期六","星期日"];
var now_weekday = weekday[date.getDay()];
document.write(year+"年"+mon+"月"+day+"日"+now_weekday)
;
如上代码为什么星期会后推一天呢
我按下面这么写就不会有问题
var mydate=new Date();
var weekday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
document.write(
mydate.getFullYear()+"年"+
( mydate.getMonth()+1)+"月"+
mydate.getDate()+"日"+
mydate.getHours()+"时"+
mydate.getMinutes()+"分"+
mydate.getSeconds()+"秒"+
weekday[mydate.getDay()]+
"<br/>"+
"<br/>"
);
星期日就是星期0,0排在1前面
date.getDay()返回的值为0到6 其中0表示星期天,1表示星期一,以此类推。
JavaScript进阶篇
468061 学习 · 21891 问题
相似问题