"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to increase date by one day in Java?

How to increase date by one day in Java?

Posted on 2025-04-29
Browse:496

How Can I Increment a Date by One Day in Java?

How to augment a date by a single day?

When you need to adjust a particular date by one day, several methods are available.

Solution 1: Utilize the Calendar Class

One approach involves the Calendar class:

Date dt = new Date();
Calendar c = Calendar.getInstance(); 
c.setTime(dt); 
c.add(Calendar.DATE, 1);
dt = c.getTime();

Solution 2: Employ the Joda-Time Library

The Joda-Time library offers a superior option due to the limitations of the Date class:

Date dt = new Date();
DateTime dtOrg = new DateTime(dt);
DateTime dtPlusOne = dtOrg.plusDays(1);

Solution 3: Leverage Java 8's JSR 310 API

Java 8 introduces the JSR 310 API:

Date dt = new Date();
LocalDateTime.from(dt.toInstant()).plusDays(1);

Solution 4: Utilize org.apache.commons.lang3.time.DateUtils

This library provides an additional method:

Date dt = new Date();
dt = DateUtils.addDays(dt, 1)
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3