字符串: sdate = 2013-07-16 13:35:02
/** * 判断给定字符串时间是否为今日 * @param sdate * @return boolean */ public static boolean isToday(String sdate){ boolean b = false; Date time = toDate(sdate); Date today = new Date(); if(time != null){ String nowDate = dateFormater2.get().format(today); String timeDate = dateFormater2.get().format(time); if(nowDate.equals(timeDate)){ b = true; } } return b; } /** * 将字符串转位日期类型 * @param sdate * @return */ public static Date toDate(String sdate) { try { return dateFormater.get().parse(sdate); } catch (ParseException e) { return null; } } private final static ThreadLocal<SimpleDateFormat> dateFormater = new ThreadLocal<SimpleDateFormat>() { @Override protected SimpleDateFormat initialValue() { return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); } }; private final static ThreadLocal<SimpleDateFormat> dateFormater2 = new ThreadLocal<SimpleDateFormat>() { @Override protected SimpleDateFormat initialValue() { return new SimpleDateFormat("yyyy-MM-dd"); } };