2010-11-22 12 views
3

日付のリストを文字列 として取得しました。たとえば、date1 - > '11-11-2010'とdate2 - > '12-01-2011 ' これらの2つの日付.. 私はcal.add()で作業しようとしましたが、私のcalに私の日付1を設定できません..もし私がnull Pを取得する場合2つの日付の間に不足している日付を見つける

+0

どのようにしましたか? – Khaled

答えて

3

以下のコードはあなたのためのトリックを行う必要があります。

String date1 = "11-11-2010"; 
    String date2 = "12-01-2011"; 

    SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy"); 
    Calendar calendar1 = Calendar.getInstance(); 
    calendar1.setTime(format.parse(date1)); 

    Calendar calendar2 = Calendar.getInstance(); 
    calendar2.setTime(format.parse(date2)); 

    Date currentDate = calendar1.getTime(); 
    while(!currentDate.equals(cal2.getTime())){ 
     calendar1.add(Calendar.DAY_OF_MONTH, 1); 
     currentDate = cal1.getTime(); 
     System.out.println(currentDate); 

    } 
+0

date2 Grozz

+0

それは完全な解決策ではありません。 fromDateとtoDateの2つの変数を切り替えることができます。 –

関連する問題