Home Java LocalDateTime Methods plusHours() Java LocalDateTime plusHours() Method Definition In Java, plusHours(hours) returns a new LocalDateTime that is the given number of hours later than the original. The minutes, seconds, and nanoseconds stay the same.
LocalDateTime is immutable , so the original object never changes. Always keep the result: dt = dt.plusHours(1);. When the hours pass midnight, the date moves forward by itself.
An instance method of java.time.LocalDateTime (since Java 8): call it on a LocalDateTime object. Add import java.time.LocalDateTime; at the top of your file.
Syntax Call it on a LocalDateTime and pass the number of hours. A negative number goes the other way.
LocalDateTime start = LocalDateTime.of(2026, 3, 15, 10, 30);
LocalDateTime result = start.plusHours(5); // 2026-03-15T15:30
System.out.println(start); // 2026-03-15T10:30 Call What it does dt.plusHours(n)Returns a new date-time with n hours added. dt.minusHours(n)The same idea in the opposite direction. dt.plus(n, ChronoUnit.HOURS)The general form. It does the same thing for this unit. time.plusHours(n)LocalTime has the same method, but it wraps around at midnight and has no date.
The result is a new object . Calling plusHours() without using the returned value does nothing useful.
Library declarations // java.time.LocalDateTime
public LocalDateTime plusHours(long hours) Parameters Parameter Description hours (long)The number of hours to add. It can be zero or negative.
Return Value Return Value Description LocalDateTimeA new LocalDateTime with the hours added. The original is not changed.
Important
LocalDateTime has no time zone, so an "hour" is always exactly 60 minutes here. Daylight saving changes are not applied. If you need them, convert with atZone() first and use ZonedDateTime.plusHours(). Any number of hours is allowed: adding 48 gives the same result as adding 2 days.
Compare with Similar Methods Methods that move a date-time in time:
Java Examples 1. Shift end 2. Across midnight 3. Hours vs days Example 1 — Find When a Shift Ends A shift starts at 09:00 and lasts eight hours. Print the start and the end.
import java.time.LocalDateTime;
public class LdtPlusHoursDemo {
public static void main(String[] args) {
LocalDateTime shiftStart = LocalDateTime.of(2026, 3, 15, 9, 0);
LocalDateTime shiftEnd = shiftStart.plusHours(8);
System.out.println("start: " + shiftStart);
System.out.println("end: " + shiftEnd);
}
} start: 2026-03-15T09:00
end: 2026-03-15T17:00 How It Works The start. The shift begins at 09:00 on 15 March 2026.Add eight hours. plusHours(8) gives 17:00 on the same day.No seconds shown. When the seconds are zero, toString() leaves them out, so you only see hours and minutes.Example 2 — Add Hours Across Midnight and New Year Add hours until the clock passes midnight, including at the end of the year.
import java.time.LocalDateTime;
public class LdtPlusHoursMidnight {
public static void main(String[] args) {
LocalDateTime late = LocalDateTime.of(2026, 3, 15, 22, 0);
LocalDateTime newYear = LocalDateTime.of(2026, 12, 31, 23, 30);
System.out.println("22:00 + 5 hours: " + late.plusHours(5));
System.out.println("23:30 + 1 hour: " + newYear.plusHours(1));
}
} 22:00 + 5 hours: 2026-03-16T03:00
23:30 + 1 hour: 2027-01-01T00:30 How It Works 22:00 plus 5 hours. The clock passes midnight, so the result is 03:00 on the next day, the 16th.The date changes by itself. You do not have to adjust the day yourself.31 December at 23:30. One more hour is 00:30 on 1 January 2027.The year changes too. The year number in the result is 2027.Example 3 — Compare Hours with Days Add 48 hours and 2 days, compare them, then add 25 hours.
import java.time.LocalDateTime;
public class LdtPlusHoursVsDays {
public static void main(String[] args) {
LocalDateTime start = LocalDateTime.of(2026, 3, 15, 10, 30);
LocalDateTime byHours = start.plusHours(48);
LocalDateTime byDays = start.plusDays(2);
System.out.println("48 hours: " + byHours);
System.out.println("2 days: " + byDays);
System.out.println("same: " + byHours.equals(byDays));
System.out.println("25 hours: " + start.plusHours(25));
}
} 48 hours: 2026-03-17T10:30
2 days: 2026-03-17T10:30
same: true
25 hours: 2026-03-16T11:30 How It Works 48 hours is two days. plusHours(48) lands on 17 March at 10:30.Same as plusDays(2). Both objects hold the same date-time, so equals prints true.Odd numbers work too. 25 hours is one day plus one hour, so the result is 16 March at 11:30.Frequently Asked Questions How do I add hours to a LocalDateTime in Java? Call dt.plusHours(n). It returns a new LocalDateTime, so store it: dt = dt.plusHours(n).
Does plusHours() change the original LocalDateTime? No. LocalDateTime is immutable, so plusHours() returns a new object and leaves the original as it was.
Can I pass a negative number to plusHours()? Yes. A negative number moves the other way, so dt.plusHours(-n) gives the same result as dt.minusHours(n).
How do I add 24 hours to a LocalDateTime in Java? Call dt.plusHours(24). It gives the same result as dt.plusDays(1).
Does plusHours() handle daylight saving time? No. LocalDateTime has no zone, so every hour is exactly 60 minutes. Use ZonedDateTime when daylight saving matters.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
10 people found this page helpful
Helpful Share Copy link Suggestion