//列出1年每个月的天数
var dateArr = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var date = new Date();
var day = date.getDate();
var month = date.getMonth(); //getMonth()是从0开始
var year = date.getFullYear();
var result = 0;
for (var i = 0; i < month; i++) {
result += dateArr[i];
}
result += day;
//判断是否闰年,如果是闰年2月份增加一天
if (month > 1 && (year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
result += 1;
}
alert(result)
var dateArr = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var date = new Date();
var day = date.getDate();
var month = date.getMonth(); //getMonth()是从0开始
var year = date.getFullYear();
var result = 0;
for (var i = 0; i < month; i++) {
result += dateArr[i];
}
result += day;
//判断是否闰年,如果是闰年2月份增加一天
if (month > 1 && (year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
result += 1;
}
alert(result)