A way to get the number of days difference between dates in Java

    @Test
    public void compareDate() throws ParseException {

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
        Date dateOne = dateFormat.parse("2020/04/24");
        Date dateTwo = dateFormat.parse("2020/05/01");
        long day = (dateOne.getTime()-dateTwo.getTime())/(1000*60*60*24);
        System.out.println("相差的天数:"+ Math.abs(day));

    }

 

Guess you like

Origin blog.csdn.net/lssqk/article/details/106743633