心语忘心
2016-12-06 11:45
var date = new Date(); // 实例化日期对象
var timeStr = '';//日期
timeStr = date.getFullYear() + "年" ;
timeStr += date.getMonth() + 1 +"月";
timeStr += date.getDate()+"日";
var day = date.getDay(); //星期
var week = '';
switch(day){
case 0 :
week = '星期一';
break;
case 1 :
week = '星期二';
break;
case 2 :
week = '星期三';
break;
case 3 :
week = '星期四';
break;
case 4 :
week = '星期五';
break;
case 5 :
week = '星期六';
break;
case 6 :
week = '星期天';
break;
}
timeStr += " "+week;
//打印出日期
document.write(timeStr);
这段代码只要一行document.write()输出就够了啊?这样
document.write(date.getFullYear()+"年"+(date.getMonth()+1)+"月"+"星期"+date.getDay());
你有可能是星期0
JavaScript进阶篇
468194 学习 · 21891 问题
相似问题