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.
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.
Output:
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:
If the result depends on timezone rules, be explicit and use ZonedDateTime:
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:
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:
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:
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
Dateas if it were a date-only type. - Forgetting that
java.timeclasses are immutable and return new values. - Using
LocalDateTimewhen the application really needsZonedDateTime. - 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
LocalDateTimeorZonedDateTimewhen time and timezone semantics matter. - Prefer
java.timeoverCalendarandDatein new code. - Remember that
java.timetypes are immutable. - Decide whether you mean the next calendar day or an exact duration before you choose the API.
Related reading
- How can I induce long full GC pause in jvm application?
- How can I initialise a static Map?
- How can I initialize an ArrayList with all zeroes in Java?
- How can I inject a property value into a Spring Bean which was configured using annotations?
- How can I instantiate a Mock Kafka Topic for junit tests?
- How can I log SQL statements in Spring Boot?
- How can I log SQL statements in Spring Boot?
- How can I lookup a Java enum from its String value?

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack 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.