获取指定日期次日凌晨日期
作者:互联网
public static void main(String[] args) throws ParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar ca=Calendar.getInstance();
Date date1 = simpleDateFormat.parse("2021-03-26 09:04:59");
ca.setTime(date1);
ca.set(Calendar.HOUR_OF_DAY, 0);
ca.set(Calendar.MINUTE, 0);
ca.set(Calendar.SECOND, 0);
ca.set(Calendar.MILLISECOND, 0);
ca.add(Calendar.DAY_OF_MONTH, 1);
Date date3 = ca.getTime();
String format = simpleDateFormat.format(date3);
System.out.println(format);
Date date2 = simpleDateFormat.parse("2021-03-25 09:04:59");
System.out.println(date1.compareTo(date2));
}
//返回结果
2021-03-27 00:00:00
标签:date1,00,set,ca,凌晨,simpleDateFormat,获取,日期,Calendar 来源: https://blog.csdn.net/qq_42980970/article/details/115195929