0

Androidで「after」メソッドを使用して2つの日付を比較しようとしています。ここに私の2つの日付があります

currentDate :Fri Sep 12 00:00:00 GMT+05:30 2014
expDate :Tue Sep 01 00:00:00 GMT+05:30 2015

私のコードは次のとおりです

private boolean checkDate(String date) throws ParseException{

    Calendar c = Calendar.getInstance(); 
    String cYear = String.valueOf(c.get(Calendar.YEAR)).substring(0, 2);
    String digit1 = date.substring(2,4);
    String digit2 = date.substring(0, 2);
    String finalDate = cYear+digit1+"-"+digit2+"-"+"01";

    SimpleDateFormat curFormater = new SimpleDateFormat("yyyy-MM-dd"); 
    Date expDate = curFormater.parse(finalDate); 

    String cDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
    Date curentDate = curFormater.parse(cDate); 

    if(curentDate.after(expDate)){
        return true;
    }else{
        return false;
    }

}

しかし、私のif条件は常にfalseを返します。コードの何が問題なのかわかりません。誰かがこれについて私を助けてください..

ありがとうございました。

4

0 に答える 0