天天看点

Android中比较两个时间的大小

/**
 * 比较当前时间和服务器返回时间大小
 *
 * @param nowDate
 * @param compareDate
 * @return
 */
public boolean compareDate(String nowDate, String compareDate) {
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm");
    try {
        Date now = df.parse(nowDate);
        Date compare = df.parse(compareDate);
        if (now.before(compare)) {
            return true;
        } else {
            return false;
        }
    } catch (ParseException e) {
        e.printStackTrace();
        return false;
    }
}