Java LocalDateTime plusHours() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Java 8+

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.

Java
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
CallWhat 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
// java.time.LocalDateTime
public LocalDateTime plusHours(long hours)

Parameters

ParameterDescription
hours (long)The number of hours to add. It can be zero or negative.

Return Value

Return ValueDescription
LocalDateTimeA new LocalDateTime with the hours added. The original is not changed.

Compare with Similar Methods

Methods that move a date-time in time:

MethodHow it differs
minusHours(n)The opposite direction for hours.
plus(n, unit)The general method: you choose the unit as an argument.
plusMinutes(n)Adds minutes for a finer step.
plusDays(n)Adds whole days. plusHours(24) gives the same result.

Java Examples

Example 1 — Find When a Shift Ends

A shift starts at 09:00 and lasts eight hours. Print the start and the end.

Java
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);
    }
}

How It Works

  1. The start. The shift begins at 09:00 on 15 March 2026.
  2. Add eight hours. plusHours(8) gives 17:00 on the same day.
  3. 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.

Java
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));
    }
}

How It Works

  1. 22:00 plus 5 hours. The clock passes midnight, so the result is 03:00 on the next day, the 16th.
  2. The date changes by itself. You do not have to adjust the day yourself.
  3. 31 December at 23:30. One more hour is 00:30 on 1 January 2027.
  4. 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.

Java
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));
    }
}

How It Works

  1. 48 hours is two days. plusHours(48) lands on 17 March at 10:30.
  2. Same as plusDays(2). Both objects hold the same date-time, so equals prints true.
  3. Odd numbers work too. 25 hours is one day plus one hour, so the result is 16 March at 11:30.

Frequently Asked Questions

Call dt.plusHours(n). It returns a new LocalDateTime, so store it: dt = dt.plusHours(n).
No. LocalDateTime is immutable, so plusHours() returns a new object and leaves the original as it was.
Yes. A negative number moves the other way, so dt.plusHours(-n) gives the same result as dt.minusHours(n).
Call dt.plusHours(24). It gives the same result as dt.plusDays(1).
No. LocalDateTime has no zone, so every hour is exactly 60 minutes. Use ZonedDateTime when daylight saving matters.

Next: plusMinutes()

Return a copy that is a number of minutes later.

plusMinutes() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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