JAVA比较指定的两个日期
Posted yvioo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JAVA比较指定的两个日期相关的知识,希望对你有一定的参考价值。
public static SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); public static SimpleDateFormat format1 = new SimpleDateFormat( "yyyyMMdd HH:mm:ss"); /** * 比较指定日期 * @param date * @param compareDate * @return 符合返回true */ public static boolean isInDate(Date date, Date compareDate) { if (compareDate.after(getStartDate(date)) && compareDate.before(getFinallyDate(date))) { return true; } else { return false; } } /** * 得到指定日期的一天的的最后时刻23:59:59 * * @param date * @return */ public static Date getFinallyDate(Date date) { String temp = format.format(date); temp += " 23:59:59"; try { return format1.parse(temp); } catch (ParseException e) { return null; } } /** * 得到指定日期的一天的开始时刻00:00:00 * * @param date * @return */ public static Date getStartDate(Date date) { String temp = format.format(date); temp += " 00:00:00"; try { return format1.parse(temp); } catch (Exception e) { return null; } }
以上是关于JAVA比较指定的两个日期的主要内容,如果未能解决你的问题,请参考以下文章