java 实现两个日期之间所有日期的遍历

来源:互联网 发布:javascript 最新版本 编辑:程序博客网 时间:2024/04/30 15:31
  1. public static void main(String[] args) {  
  2.   
  3.     Calendar start = Calendar.getInstance();  
  4.     start.set(2016,310);  
  5.     Long startTIme = start.getTimeInMillis();  
  6.   
  7.     Calendar end = Calendar.getInstance();  
  8.     end.set(2016,410);  
  9.     Long endTime = end.getTimeInMillis();  
  10.   
  11.     Long oneDay = 1000 * 60 * 60 * 24l;  
  12.   
  13.     Long time = startTIme;  
  14.     while (time <= endTime) {  
  15.         Date d = new Date(time);  
  16.         DateFormat df = new SimpleDateFormat("yyyy-MM-dd");  
  17.         System.out.println(df.format(d));  
  18.         time += oneDay;  
  19.     }  
  20. }  
0 0