小珊1116
2016-05-24 16:35
为什么算月份的时候后面要+1啊?
var mydate= new Date();
var myyear=mydate.getFullYear();
var mymonth=mydate.getMonth()+1;
var mynum=mydate.getDay();
var weekday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六",]
document.write(mydate+"<br>");
document.write(myyear+"<br>");
document.write(mymonth+"<br>");
document.write(myyear+"年"+mymonth+"月"+mynum+"日"+weekday[mynum]+"<br>");
我这么输出的日期怎么不对呢?
month是从0开始的
document.write(sum);
var mydate=new Date();
var myYear=mydate.getFullYear()+"年";
var myMonth=mydate.getMonth()+"月";
var myTime=mydate.getDate()+"日";
var weekday=['星期日','星期一','星期二','星期三','星期四','星期五','星期六'];
var myday=weekday[mydate.getDay()];
document.write(myYear+myMonth+myTime+myday+"<br>");
var scoreStr = "小明:87;小花:81;小红:97;小天:76;小张:74;小小:94;小西:90;小伍:76;小迪:64;小曼:76";
var scoreArr=scoreStr.split(";");
document.write(scoreArr);
var sum=0;
for( var i=0;i<scoreArr.length;i++);
{
var index=scoreArr[i].indexOf(":");
document.write(index);
sum+=parseInt(scoreArr[i].substr(index+1,2));
document.write(sum);
}
document.write("班级平均分为:"+Math.round(sum/scoreArr.length));
JavaScript进阶篇
468061 学习 · 21891 问题
相似问题