今早看园友的文章八百年一次……,心想到底是不是八百年一遇,就用js自己验证了一下;
园友判断有5个礼拜五,5个礼拜六,5个礼拜天的方法:
1:该月必须有31天
2:该月1号必须是星期5. (我的判断是最后一天是星期天,求最后一天是为了方便判断这个月有的天数)
<script>
//move back one month
function prevMonth(thisMonth, thisYear) {
if (thisMonth == 1) {
thisM = 12;
thisY = (thisYear - 1);
}
else {
thisM = (thisMonth - 1);
thisY = thisYear;
}
}
//move forward one month
function nextMonth(thisMonth, thisYear) {
if (thisMonth == 12) {
thisM = 1;
thisY = (thisYear + 1)
}
else {
thisM = (thisMonth + 1);
thisY = thisYear;
}
}
//转化为短的日期格式
function toShortDate(date) {
var dateStr = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
return dateStr;
}
var dtNow = new Date();
var thisM = dtNow.getMonth()+1;
var thisY = dtNow.getFullYear();
var arrayRecord = [];
while (thisY >= 1900) {
prevMonth(thisM, thisY);
var lastDayOfPrevMonth = new Date(thisY, thisM, 0);
if (lastDayOfPrevMonth.getDay() == 0 && lastDayOfPrevMonth.getDate() == 31) {
arrayRecord.push(toShortDate(lastDayOfPrevMonth));
}
}
document.write(arrayRecord.join("\r"));
</script>
//move back one month
function prevMonth(thisMonth, thisYear) {
if (thisMonth == 1) {
thisM = 12;
thisY = (thisYear - 1);
}
else {
thisM = (thisMonth - 1);
thisY = thisYear;
}
}
//move forward one month
function nextMonth(thisMonth, thisYear) {
if (thisMonth == 12) {
thisM = 1;
thisY = (thisYear + 1)
}
else {
thisM = (thisMonth + 1);
thisY = thisYear;
}
}
//转化为短的日期格式
function toShortDate(date) {
var dateStr = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
return dateStr;
}
var dtNow = new Date();
var thisM = dtNow.getMonth()+1;
var thisY = dtNow.getFullYear();
var arrayRecord = [];
while (thisY >= 1900) {
prevMonth(thisM, thisY);
var lastDayOfPrevMonth = new Date(thisY, thisM, 0);
if (lastDayOfPrevMonth.getDay() == 0 && lastDayOfPrevMonth.getDate() == 31) {
arrayRecord.push(toShortDate(lastDayOfPrevMonth));
}
}
document.write(arrayRecord.join("\r"));
</script>
先前一次七月份有五个周五,五个周六,五个周天是:
2005-7感谢你留言,转载请声明出处(http://www.cnblogs.com/flowerszhong/)。