Java LocalDateTime minusSeconds() Method

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

Definition

In Java, minusSeconds(seconds) returns a new LocalDateTime that is the given number of seconds earlier than the original. The nanoseconds stay the same.

LocalDateTime is immutable, so the original object never changes. Always keep the result: dt = dt.minusSeconds(1);. When the seconds go back past the start of a minute, the minute changes, and the hour and the date follow when needed.

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 seconds. A negative number goes the other way.

Java
LocalDateTime start = LocalDateTime.of(2026, 3, 15, 10, 30);
LocalDateTime result = start.minusSeconds(30);   // 2026-03-15T10:29:30
System.out.println(start);   // 2026-03-15T10:30
CallWhat it does
dt.minusSeconds(n)Returns a new date-time with n seconds subtracted.
dt.plusSeconds(n)The same idea in the opposite direction.
dt.minus(n, ChronoUnit.SECONDS)The general form. It does the same thing for this unit.
time.minusSeconds(n)LocalTime has the same method, but it wraps around at midnight and has no date.

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

Library declarations
Java
// java.time.LocalDateTime
public LocalDateTime minusSeconds(long seconds)

Parameters

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

Return Value

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

Compare with Similar Methods

Methods that move a date-time in time:

MethodHow it differs
plusSeconds(n)The opposite direction for seconds.
minus(n, unit)The general method: you choose the unit as an argument.
minusMinutes(n)Subtracts minutes for a bigger step.
minusNanos(n)Subtracts nanoseconds for a much finer step.

Java Examples

Example 1 — Look Back a Few Seconds

Take the moment 10:30 and print the time 30 and 90 seconds earlier.

Java
import java.time.LocalDateTime;

public class LdtMinusSecondsDemo {
    public static void main(String[] args) {
        LocalDateTime now = LocalDateTime.of(2026, 3, 15, 10, 30);

        System.out.println("now:        " + now);
        System.out.println("30 s ago:   " + now.minusSeconds(30));
        System.out.println("90 s ago:   " + now.minusSeconds(90));
    }
}

How It Works

  1. The starting moment. 10:30 with zero seconds.
  2. 30 seconds back. The minute goes back to 10:29 and the seconds show as :30.
  3. 90 seconds back. That is one and a half minutes, so the result is 10:28:30.

Example 2 — Go Back Across a Minute and a Year

Subtract seconds from just after the hour, and from the first moment of a new year.

Java
import java.time.LocalDateTime;

public class LdtMinusSecondsRollover {
    public static void main(String[] args) {
        LocalDateTime hour = LocalDateTime.of(2026, 3, 15, 10, 0, 10);
        LocalDateTime year = LocalDateTime.of(2027, 1, 1, 0, 0, 0);

        System.out.println("10:00:10 - 20s: " + hour.minusSeconds(20));
        System.out.println("00:00:00 - 1s:  " + year.minusSeconds(1));
    }
}

How It Works

  1. 10:00:10 minus 20 seconds. The time goes back past the hour, so the result is 09:59:50.
  2. The first second of 2027. One second earlier is the last second of 2026.
  3. Date and year follow. The result is 31 December 2026 at 23:59:59.

Example 3 — See Seconds Disappear from the Text

Subtract 45 seconds from 10:30:45, and compare 3600 seconds with one hour.

Java
import java.time.LocalDateTime;

public class LdtMinusSecondsHidden {
    public static void main(String[] args) {
        LocalDateTime base = LocalDateTime.of(2026, 3, 15, 10, 30, 45);

        System.out.println("before:      " + base);
        System.out.println("minus 45 s:  " + base.minusSeconds(45));
        System.out.println("3600 s = 1 h: " + base.minusSeconds(3600).equals(base.minusHours(1)));
    }
}

How It Works

  1. The starting moment. 10:30:45, so the seconds are printed.
  2. Subtract 45 seconds. That leaves exactly 10:30 and zero seconds.
  3. The text gets shorter. toString() hides zero seconds, so the result prints as 10:30.
  4. 3600 seconds is one hour. minusSeconds(3600) equals minusHours(1), so the last line prints true.

Frequently Asked Questions

Call dt.minusSeconds(n). It returns a new LocalDateTime, so store it: dt = dt.minusSeconds(n).
No. LocalDateTime is immutable, so minusSeconds() returns a new object and leaves the original as it was.
Yes. A negative number moves the other way, so dt.minusSeconds(-n) gives the same result as dt.plusSeconds(n).
Use LocalDateTime.now().minusSeconds(10).
toString() leaves out the seconds when they are zero. The value is the same; use format() with the pattern HH:mm:ss to always show them.

Next: minusWeeks()

Return a copy that is a number of weeks earlier.

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

9 people found this page helpful