var now = new Date();
3 var year = now.getFullYear(); //得到年份 四位格式yyyy
4 var month = now.getMonth();//得到月份
5 var date = now.getDate();//得到日期
6 var day = now.getDay();//得到周几
7 var hour = now.getHours();//得到小时
8 var minu = now.getMinutes();//得到分钟
9 var sec = now.getSeconds();//得到秒
10 var MS = now.getMilliseconds();//获取毫秒
需求:获取month的长度做判断,如果为1为则前补0
直接使用length是不可以的,要先使用toString转为string类型在使用length
结果: month .toString().length