首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

依据当前年月份获取当年的该月的所有日期号

2012-11-06 
根据当前年月份获取当年的该月的所有日期号List list AllDayOfMonth(new java.text.SimpleDateFormat(y

根据当前年月份获取当年的该月的所有日期号
List list = AllDayOfMonth(new java.text.SimpleDateFormat("yyyy-MM").parse( "2010-09-09" ));
public static List AllDayOfMonth(Date date){
Calendar c = Calendar.getInstance();
c.setTime(date);
c.set(Calendar.DATE, 1);
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
int firstday = c.get(Calendar.DAY_OF_MONTH);

Calendar lc = Calendar.getInstance();
lc.setTime(date);
lc.add(Calendar.MONTH, 1);
lc.set(Calendar.DATE, 0);
lc.set(Calendar.HOUR_OF_DAY, 23);
lc.set(Calendar.MINUTE, 59);
lc.set(Calendar.SECOND, 59);
lc.set(Calendar.MILLISECOND, 999);
int lastday = lc.get(Calendar.DAY_OF_MONTH);

Calendar nowDate = Calendar.getInstance();
nowDate.setTime(date);
List list = new ArrayList();
for(int i =1;i<2+lastday-firstday;i++){
nowDate.set(Calendar.DAY_OF_MONTH, i);
list.add(new java.text.SimpleDateFormat("yyyy-MM-dd").format(nowDate.getTime()));
}
return list;
}

热点排行