已知一個日期,yyyy-MM-dd格式,從當前日期倒推num天,返回這一日期集合

 
  1.   已知一個日期,yyyy-MM-dd格式,從當前日期倒推num天,返回這一日期集合   
  2. public static List<String> getOneWeekByEndDate(String endDate, int num) {   
  3.         String y = endDate.substring(04);   
  4.         String m = endDate.substring(57);   
  5.         String d = endDate.substring(810);   
  6.         int year = Integer.parseInt(y);   
  7.         int month = Integer.parseInt(m);   
  8.         int date = Integer.parseInt(d);   
  9.   
  10.         List<String> list = new ArrayList<String>();   
  11.         Calendar c = new GregorianCalendar(year, month - 1, date);   
  12.         list.add(endDate);   
  13.         for (int i = 0; i < num; i++) {   
  14.             c.add(GregorianCalendar.DATE, -1);   
  15.             String time = formatDate(c.getTime());   
  16.   
  17.             list.add(time);   
  18.   
  19.         }   
  20.   
  21.         return list;   
  22.   
  23.     }  
發佈了9 篇原創文章 · 獲贊 2 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章