How to add One Day to a Date in Java


Let us take a look at how to add one day to a Date or LocalDate object in Java with examples.


Example 1: Using Data (Java 7 or below)

public static void main(String... args) {

        Date currentDate = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(currentDate);

        calendar.add(Calendar.DAY_OF_MONTH, 1);

        Date tomorrowDate = calendar.getTime();
        System.out.println("Current Date: " + currentDate);
        System.out.println("Tomorrow's Date: " + tomorrowDate);

}
Output:

Current Date: Wed Oct 17 13:41:03 CDT 2023
Tomorrow's Date: Thu Oct 18 13:41:03 CDT 2023


Example 2: Using LocalDate (Java 8 and above)

public static void main(String... args) {

        LocalDate currentDate = LocalDate.now();

        LocalDate tomorrowDate = currentDate.plusDays(1);

        System.out.println("Current Date: " + currentDate);
        System.out.println("Tomorrow's Date: " + tomorrowDate);

}
Java Add One Day to LocalDate Example

Note: LocalDate is the preferred and recommended way of dealing with Date and Time since Java 8.

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap