Java
Programming
Date Manipulation
Coding Tips
Incrementing Dates

How can I increment a date by one day in Java?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Adding one day to a date sounds trivial, but the correct Java API depends on what kind of value you actually have. For modern code, java.time is the right starting point because it is immutable, clearer to read, and safer than the legacy date APIs.

Use LocalDate.plusDays(1) for Date-Only Values

If you only care about a calendar date and not a time of day or timezone, use LocalDate.

java
1import java.time.LocalDate;
2
3public class Main {
4    public static void main(String[] args) {
5        LocalDate today = LocalDate.of(2025, 1, 31);
6        LocalDate tomorrow = today.plusDays(1);
7
8        System.out.println(today);
9        System.out.println(tomorrow);
10    }
11}

Output:

text
2025-01-31
2025-02-01

This is the normal answer for business dates such as due dates, booking dates, and report periods.

When Time of Day Matters

If the value also includes a time, use LocalDateTime or ZonedDateTime depending on whether timezone rules matter.

Example with LocalDateTime:

java
1import java.time.LocalDateTime;
2
3public class Main {
4    public static void main(String[] args) {
5        LocalDateTime now = LocalDateTime.of(2025, 3, 10, 18, 30);
6        LocalDateTime nextDay = now.plusDays(1);
7
8        System.out.println(nextDay);
9    }
10}

If the result depends on timezone rules, be explicit and use ZonedDateTime:

java
1import java.time.ZoneId;
2import java.time.ZonedDateTime;
3
4public class Main {
5    public static void main(String[] args) {
6        ZonedDateTime start = ZonedDateTime.of(
7            2025, 3, 8, 12, 0, 0, 0,
8            ZoneId.of("America/Toronto")
9        );
10
11        ZonedDateTime nextDay = start.plusDays(1);
12        System.out.println(nextDay);
13    }
14}

That distinction matters because "one calendar day later" is not always the same as "add exactly 24 hours" in a real timezone.

Avoid Adding Raw Milliseconds

This kind of code is tempting:

java
long tomorrowMillis = System.currentTimeMillis() + 24L * 60 * 60 * 1000;

It is usually the wrong tool for date logic. It ignores calendar semantics, weakens readability, and can behave badly around daylight-saving transitions when what you really meant was "the next calendar day."

If you mean an exact duration, use a duration type. If you mean the next date, use a date API.

Legacy APIs Still Exist, But Prefer Conversion

Older Java code often uses Calendar:

java
1import java.util.Calendar;
2
3public class Main {
4    public static void main(String[] args) {
5        Calendar calendar = Calendar.getInstance();
6        calendar.set(2025, Calendar.JANUARY, 31);
7        calendar.add(Calendar.DAY_OF_MONTH, 1);
8
9        System.out.println(calendar.getTime());
10    }
11}

This works, but Calendar is mutable and harder to reason about. If you are writing new code, prefer java.time.

If you are stuck with java.util.Date, convert it as early as practical:

java
1import java.time.Instant;
2import java.time.LocalDate;
3import java.time.ZoneId;
4import java.util.Date;
5
6public class Main {
7    public static void main(String[] args) {
8        Date legacyDate = new Date();
9
10        LocalDate localDate = Instant.ofEpochMilli(legacyDate.getTime())
11            .atZone(ZoneId.systemDefault())
12            .toLocalDate();
13
14        LocalDate nextDay = localDate.plusDays(1);
15        System.out.println(nextDay);
16    }
17}

That conversion step usually makes later logic much easier to maintain.

Clarify What "One Day" Means

The most important design question is semantic, not syntactic. Do you mean:

  • the next calendar date
  • exactly 24 hours later
  • the next business day

Those are different operations. A correct Java solution starts by choosing the right meaning before choosing the method call.

Common Pitfalls

  • Using Date as if it were a date-only type.
  • Forgetting that java.time classes are immutable and return new values.
  • Using LocalDateTime when the application really needs ZonedDateTime.
  • Adding raw milliseconds when the requirement is a calendar-based increment.
  • Solving the syntax while ignoring the actual meaning of "one day."

Summary

  • Use LocalDate.plusDays(1) for normal date-only logic.
  • Use LocalDateTime or ZonedDateTime when time and timezone semantics matter.
  • Prefer java.time over Calendar and Date in new code.
  • Remember that java.time types are immutable.
  • Decide whether you mean the next calendar day or an exact duration before you choose the API.

Related reading
Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.