var currentDate = new Date(); var weekday = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]; document.write( currentDate.getFullYear() + "年" + (currentDate.getMonth() + 1) + "月" + currentDate.getDate() + "日" + " " + weekday[currentDate.getDay()] );
为什么(currentDate.getMonth() + 1) + "月" 这句要加括号才可以呢,而且我试了一下在外面单独写可以,为啥呢
知道了。因为加括号月份可以加1