判断从数据库取到的时间是否晚于当前时间
/**
* 格式化字符串为Date类型
* @param str_date
* @return
*/
private static Date getDateFromStr(String str_date){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date =(Date)sdf.parse(str_date);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
/**
* 比较该事件是否晚于当前时间
* @param dateStr
* @return
*/
private static boolean isAfterNow(String dateStr){
boolean flag = false;
Date strDate = getDateFromStr(dateStr);//"2010-08-12 00:25:55"
Calendar nowCalendar = Calendar.getInstance();
nowCalendar.setTime(new Date());
Calendar strCalendar = Calendar.getInstance();
strCalendar.setTime(strDate);
flag = strCalendar.after(nowCalendar);
return flag;
}
public static void main(String[] args) {
System.out.println(isAfterNow("2012-08-12 00:25:55"));
}