Java LocalDateTime minusHours() Method

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

Definition

In Java, minusHours(hours) returns a new LocalDateTime that is the given number of hours earlier 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.minusHours(1);. When the hours go back past midnight, the date moves back 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.minusHours(3);   // 2026-03-15T07:30
System.out.println(start);   // 2026-03-15T10:30
CallWhat it does
dt.minusHours(n)Returns a new date-time with n hours subtracted.
dt.plusHours(n)The same idea in the opposite direction.
dt.minus(n, ChronoUnit.HOURS)The general form. It does the same thing for this unit.
time.minusHours(n)LocalTime has the same method, but it wraps around at midnight and has no date.

The result is a new object. Calling minusHours() without using the returned value does nothing useful.

Library declarations
Java
// java.time.LocalDateTime
public LocalDateTime minusHours(long hours)

Parameters

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

Return Value

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

Compare with Similar Methods

Methods that move a date-time in time:

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

Java Examples

Example 1 — Find When the Doors Open

A show starts at 18:00 and the doors open three hours earlier. Print both times.

Java
import java.time.LocalDateTime;

public class LdtMinusHoursDemo {
    public static void main(String[] args) {
        LocalDateTime showStart = LocalDateTime.of(2026, 3, 15, 18, 0);
        LocalDateTime doorsOpen = showStart.minusHours(3);

        System.out.println("show starts: " + showStart);
        System.out.println("doors open:  " + doorsOpen);
    }
}

How It Works

  1. The show. It starts at 18:00 on 15 March 2026.
  2. Three hours earlier. minusHours(3) gives 15:00 on the same day.
  3. A new object. The show time stored in showStart is not changed.

Example 2 — Go Back Past Midnight and New Year

Subtract hours from early-morning times so the date has to move back.

Java
import java.time.LocalDateTime;

public class LdtMinusHoursMidnight {
    public static void main(String[] args) {
        LocalDateTime early = LocalDateTime.of(2026, 3, 15, 2, 0);
        LocalDateTime newYear = LocalDateTime.of(2027, 1, 1, 0, 30);

        System.out.println("02:00 - 3 hours: " + early.minusHours(3));
        System.out.println("00:30 - 1 hour:  " + newYear.minusHours(1));
    }
}

How It Works

  1. 02:00 minus 3 hours. The clock goes back past midnight, so the result is 23:00 on the 14th.
  2. The date moves back by itself. You never adjust the day by hand.
  3. 00:30 on 1 January. One hour earlier is 23:30 on 31 December 2026.
  4. The year goes back too. The result is in 2026, not 2027.

Example 3 — Shift a UTC Time by a Fixed Number of Hours

Subtract 5 hours from a UTC moment to see a clock 5 hours behind, and compare 24 hours with 1 day.

Java
import java.time.LocalDateTime;

public class LdtMinusHoursOffset {
    public static void main(String[] args) {
        LocalDateTime utc = LocalDateTime.of(2026, 3, 15, 12, 0);

        System.out.println("UTC:             " + utc);
        System.out.println("5 hours behind:  " + utc.minusHours(5));
        System.out.println("24 hours = 1 day: " + utc.minusHours(24).equals(utc.minusDays(1)));
    }
}

How It Works

  1. A UTC moment. Noon on 15 March 2026, stored without a zone.
  2. A fixed shift. minusHours(5) shows the clock of a place that is always exactly five hours behind: 07:00.
  3. 24 hours is one day. Because there is no zone, minusHours(24) equals minusDays(1), so the last line prints true.

Frequently Asked Questions

Call dt.minusHours(n). It returns a new LocalDateTime, so store it: dt = dt.minusHours(n).
No. LocalDateTime is immutable, so minusHours() returns a new object and leaves the original as it was.
Yes. A negative number moves the other way, so dt.minusHours(-n) gives the same result as dt.plusHours(n).
Use LocalDateTime.now().minusHours(1).
For a LocalDateTime, yes. With a ZonedDateTime they can differ on a daylight saving change day.

Next: minusMinutes()

Return a copy that is a number of minutes earlier.

minusMinutes() 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.

14 people found this page helpful