Java LocalDateTime plusSeconds() Method

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

Definition

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

LocalDateTime is immutable, so the original object never changes. Always keep the result: dt = dt.plusSeconds(1);. When the seconds pass 60, 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.plusSeconds(45);   // 2026-03-15T10:30:45
System.out.println(start);   // 2026-03-15T10:30
CallWhat it does
dt.plusSeconds(n)Returns a new date-time with n seconds added.
dt.minusSeconds(n)The same idea in the opposite direction.
dt.plus(n, ChronoUnit.SECONDS)The general form. It does the same thing for this unit.
time.plusSeconds(n)LocalTime has the same method, but it wraps around at midnight and has no date.

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

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

Parameters

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

Return Value

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

Compare with Similar Methods

Methods that move a date-time in time:

MethodHow it differs
minusSeconds(n)The opposite direction for seconds.
plus(n, unit)The general method: you choose the unit as an argument.
plusMinutes(n)Adds minutes for a bigger step.
plusNanos(n)Adds nanoseconds for a much finer step.

Java Examples

Example 1 — Work Out a Timeout

A login code is created at 10:30 and expires 45 seconds later. Print both moments.

Java
import java.time.LocalDateTime;

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

        System.out.println("created: " + created);
        System.out.println("expires: " + expires);
    }
}

How It Works

  1. The creation time. 10:30 on 15 March 2026, with zero seconds.
  2. Add 45 seconds. plusSeconds(45) gives 10:30:45.
  3. Seconds appear when they matter. The first line shows no seconds because they are zero, and the second line shows :45.

Example 2 — See When Seconds Are Hidden

Add 0, 60, and 61 seconds and watch how the printed text changes.

Java
import java.time.LocalDateTime;

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

        System.out.println("+0 seconds:  " + base.plusSeconds(0));
        System.out.println("+60 seconds: " + base.plusSeconds(60));
        System.out.println("+61 seconds: " + base.plusSeconds(61));
    }
}

How It Works

  1. Adding zero. The result equals the original and prints without seconds.
  2. 60 seconds is one minute. The minute changes to 31 and the seconds are zero again, so they stay hidden.
  3. 61 seconds. One minute and one second, so the text shows 10:31:01.

Example 3 — Add Seconds Across a Minute and a Year

Roll over to the next minute, over the end of the year, and compare 3600 seconds with one hour.

Java
import java.time.LocalDateTime;

public class LdtPlusSecondsRollover {
    public static void main(String[] args) {
        LocalDateTime a = LocalDateTime.of(2026, 3, 15, 10, 59, 50);
        LocalDateTime b = LocalDateTime.of(2026, 12, 31, 23, 59, 59);

        System.out.println("10:59:50 + 20s: " + a.plusSeconds(20));
        System.out.println("23:59:59 + 1s:  " + b.plusSeconds(1));
        System.out.println("3600s equals 1h: " + a.plusSeconds(3600).equals(a.plusHours(1)));
    }
}

How It Works

  1. 10:59:50 plus 20 seconds. The minute and the hour both roll over, giving 11:00:10.
  2. The last second of the year. One more second is midnight on 1 January 2027, which prints as 00:00.
  3. 3600 seconds is one hour. plusSeconds(3600) and plusHours(1) give equal results, so the last line prints true.

Frequently Asked Questions

Call dt.plusSeconds(n). It returns a new LocalDateTime, so store it: dt = dt.plusSeconds(n).
No. LocalDateTime is immutable, so plusSeconds() returns a new object and leaves the original as it was.
Yes. A negative number moves the other way, so dt.plusSeconds(-n) gives the same result as dt.minusSeconds(n).
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.
Call plusSeconds(3600). It gives the same result as plusHours(1).

Next: plusWeeks()

Return a copy that is a number of weeks later.

plusWeeks() 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