public static boolean dateCompare(String dateStr)
{
Calendar calendar = Calendar.getInstance();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(TimeFormatPattern.DEFAULT);
Date date = null;
try
{
date = simpleDateFormat.parse(dateStr);
} catch (ParseException e)
{
LOGGER.error("日期格式化错误"+e.getMessage());
}
calendar.setTime(date);
calendar.add(Calendar.DATE, 1);
if(!calendar.after(new Date())){
LOGGER.info("日期没有超过当前时间一天,无法进行下面的操作");
return false;
}
return true;
}
时间操作(一)
本文介绍了一个用于验证日期是否不超过当前日期一天的Java方法。通过使用`SimpleDateFormat`进行日期格式化和`Calendar`进行日期比较,确保在进行后续操作前日期的有效性。方法中包含了异常处理机制,确保了程序的健壮性。

被折叠的 条评论
为什么被折叠?



