获取指定日期次日凌晨日期

 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



上一篇:java Date日期类型与字符串 转换


下一篇:2021.10.06知识点