DateUtil tool class time offset in Hutool

Get the previous year today or the next year today, etc.

        Date date = new Date();
        // 返回的格式就是2020-01-01格式,如果后面的数字是负数,就是往以前的时间移动
        Date month = DateUtil.offsetMonth(date, 12);
        Date day = DateUtil.offsetDay(date, 10);
        System.out.println(month);
        System.out.println(day);

Output:
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_45850872/article/details/111473591