0

我正在尝试使用 android 中的“after”方法比较两个日期。这是我的两个约会

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