var date = new Date(); var weekday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]; var mynum=date.getDay(1) var timeStr = ''; timeStr = date.getFullYear() + "年" ; timeStr += date.getMonth() + 1 +"月"; timeStr += date.getDate()+"日"; timeStr += weekday[mydate.getDay(1)]; document.write(timeStr);为什么这样子显示不了星期一var date = new Date(); var weekday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]; var mynum=date.getDay(1) var timeStr = ''; timeStr = date.getFullYear() + "年" ; timeStr += date.getMonth() + 1 +"月"; timeStr += date.getDate()+"日"; timeStr += weekday[mynum]; document.write(timeStr);这样子可以显示星期一了,为什么呢另外我年月日没写就自动显示了,求解
3 回答
stone310
TA贡献361条经验 获得超191个赞
你mydate没定义啊,之前定义的是date=new Date();mydate改成date就好了;
另外年月日不是写了date.getFullYear+"年"这些吗;timeStr += XXX这个是自相加,timerStr=timeStr+XXX,所以年月日就会显示了
super丶千
TA贡献5条经验 获得超1个赞
timeStr += weekday[mydate.getDay(1)]; 与 timeStr += weekday[mynum]; 有区别!将timeStr += weekday[mydate.getDay(1)]; 改成date.getDay(1)就可以了!
添加回答
举报
0/150
提交
取消