Home Java LocalDateTime Methods minusHours() Java LocalDateTime minusHours() Method 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.
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 Call What 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.time.LocalDateTime
public LocalDateTime minusHours(long hours) Parameters Parameter Description hours (long)The number of hours to subtract. It can be zero or negative.
Return Value Return Value Description LocalDateTimeA new LocalDateTime with the hours subtracted. The original is not changed.
Important
LocalDateTime has no time zone, so an "hour" is always exactly 60 minutes here, and daylight saving changes are not applied. Subtracting hours is not a safe way to convert between time zones: use atZone() with a ZoneId for that.
Compare with Similar Methods Methods that move a date-time in time:
Java Examples 1. Doors open 2. Back across midnight 3. Fixed hour offset Example 1 — Find When the Doors Open A show starts at 18:00 and the doors open three hours earlier. Print both times.
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);
}
} show starts: 2026-03-15T18:00
doors open: 2026-03-15T15:00 How It Works The show. It starts at 18:00 on 15 March 2026.Three hours earlier. minusHours(3) gives 15:00 on the same day.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.
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));
}
} 02:00 - 3 hours: 2026-03-14T23:00
00:30 - 1 hour: 2026-12-31T23:30 How It Works 02:00 minus 3 hours. The clock goes back past midnight, so the result is 23:00 on the 14th.The date moves back by itself. You never adjust the day by hand.00:30 on 1 January. One hour earlier is 23:30 on 31 December 2026.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.
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)));
}
} UTC: 2026-03-15T12:00
5 hours behind: 2026-03-15T07:00
24 hours = 1 day: true How It Works A UTC moment. Noon on 15 March 2026, stored without a zone.A fixed shift. minusHours(5) shows the clock of a place that is always exactly five hours behind: 07:00.24 hours is one day. Because there is no zone, minusHours(24) equals minusDays(1), so the last line prints true.Frequently Asked Questions How do I subtract hours from a LocalDateTime in Java? Call dt.minusHours(n). It returns a new LocalDateTime, so store it: dt = dt.minusHours(n).
Does minusHours() change the original LocalDateTime? No. LocalDateTime is immutable, so minusHours() returns a new object and leaves the original as it was.
Can I pass a negative number to minusHours()? Yes. A negative number moves the other way, so dt.minusHours(-n) gives the same result as dt.plusHours(n).
How do I subtract 1 hour from the current time in Java? Use LocalDateTime.now().minusHours(1).
Is minusHours(24) the same as minusDays(1)? For a LocalDateTime, yes. With a ZonedDateTime they can differ on a daylight saving change day.
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.
14 people found this page helpful
Helpful Share Copy link Suggestion