1、Java日期循环
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
String dateStr1="2008-3-16";
String dateStr2="2008-3-24";
java.util.Date dateBegin=formater.parse(dateStr1);
java.util.Date dateEnd=formater.parse(dateStr2);
Calendar ca=Calendar.getInstance();
while(dateBegin.compareTo(dateEnd)<=0){
ca.setTime(dateBegin);
ca.add(ca.DATE,1);//把dateBegin加上1天然后重新赋值给date1
dateBegin=ca.getTime();
}
2、Java获取当月的第一天和最后一天
Calendar cal = Calendar.getInstance();
SimpleDateFormat datef=new SimpleDateFormat("yyyy-MM-dd");
//当前月的最后一天
cal.set( Calendar.DATE, 1 );
cal.roll(Calendar.DATE, - 1 );
Date endTime=cal.getTime();
String endTime1=datef.format(endTime)+" 23:59:59";
//当前月的第一天
cal.set(GregorianCalendar.DAY_OF_MONTH, 1);
Date beginTime=cal.getTime();
String beginTime1=datef.format(beginTime)+" 00:00:00";