public static List<String> getBetweenDays(String stime,String etime){
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
Date sdate=null;
Date eDate=null;
try {
sdate=df.parse(stime);
eDate=df.parse(etime);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long betweendays=(long) ((eDate.getTime()-sdate.getTime())/(1000 * 60 * 60 *24)+0.5);//天数间隔
Calendar c = Calendar.getInstance();
List<String> list=new ArrayList<String>();
while (sdate.getTime()<=eDate.getTime()) {
list.add(df.format(sdate));
System.out.println(df.format(sdate));
c.setTime(sdate);
c.add(Calendar.DATE, 1); // 日期加1天
sdate = c.getTime();
}
return list;
}
java获取两个字符串日期之间的时间间隔天数,以及遍历这些天数
最新推荐文章于 2024-05-27 00:20:08 发布