一、获取某年各月的最后一天
function getMonthLastDay(year){
var lastMonthDay = [];
year = ( year < 1900 ) ? ( 1900 +year ) : year;
var tempDate = new Date();
var tempYear = tempDate.getYear();
for(month=0; month<12; month++){
tempDate = new Date();
tempDate.setYear(year);
tempDate.setMonth(month+1);
tempDate.setDate(0);
tempYear = tempDate.getYear();
tempYear = ( tempYear < 1900 ) ? ( 1900 +tempYear ) : tempYear;
lastMonthDay.push(tempYear+"-"+(tempDate.getMonth()+1)+"-"+tempDate.getDate());
}
return lastMonthDay;
}
例如: 获取2014年每个月最后一天的日期
document.write(getMonthLastDay('2014').join(','));
返回结果:2014-1-31,2014-2-28,2014-3-31,2014-4-30,2014-5-31,2014-6-30,2014-7-31,2014-8-31,2014-9-30,2014-10-31,2014-11-30,2014-12-31
二、获取一段时间日期中是星期五的日期
这里用ExtJS的Ext.Date的方法去实现
function getFriday(beginDate, endDate){
friday = [];
date1 = Ext.Date.parse(beginDate, 'Y-m-d');
date2 = Ext.Date.parse(endDate, 'Y-m-d');
//计算两天相差多少天
diffday = (date2-date1)/86400000;
for(i=1; i<=diffday; i++){
date3 = Ext.Date.add(date1,Ext.Date.DAY, i);
if(date3.getDay()==5){ //星期五
friday.push(Ext.Date.format(date3,'Y-m-d'));
}
}
return friday;
}
例如:获取2014-04-01至2014-06-01这段时间是星期五的日期
document.write(getFriday('2014-04-01','2014-06-01').join(','));
返回结果:2014-04-04,2014-04-11,2014-04-18,2014-04-25,2014-05-02,2014-05-09,2014-05-16,2014-05-23,2014-05-30