/** * 比较两个日期的大小: * 2 发生异常 * 1 firstDate>secondDate * 0 firstDate==secondDate * -1 firstDate<secondDate * @param format * @param firstDate * @param secondDate * @return */ public static int compareDate(String format,String firstDate, String secondDate){ SimpleDateFormat sdf = new SimpleDateFormat(format); int result = 2; try { Date fDate = sdf.parse(firstDate); Date sDate = sdf.parse(secondDate); if(fDate.getTime()>sDate.getTime()){ result = 1; }else if(fDate.getTime()==sDate.getTime()){ result = 0; }else{ result = -1; } } catch (ParseException ex) { Logger.getLogger(DateUtil.class.getName()).log(Level.SEVERE, null, ex); } return result; }