String s1 = "2012-02-01"; String s2 = "2012-04-04"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date begin=sdf.parse(s1); Date end=sdf.parse(s2); double between=(end.getTime()-begin.getTime())/1000;//除以1000是为了转换成秒 double day=between/(24*3600); for(int i = 1;i<=day;i++){
Calendar cd = Calendar.getInstance(); cd.setTime(sdf.parse(s1)); cd.add(Calendar.DATE, i);//增加一天 //cd.add(Calendar.MONTH, n);//增加一个月 System.out.println(sdf.format(cd.getTime())); }
|