Java Date Time - Duration plusSeconds(long secondsToAdd) example








Duration plusSeconds(long secondsToAdd) returns a copy of this duration with the specified duration in seconds added.

Syntax

plusSeconds has the following syntax.

public Duration plusSeconds(long secondsToAdd)

Example

The following example shows how to use plusSeconds.

import java.time.Duration;
import java.time.LocalTime;
/*from   w w w.  j  a v a2  s.  co  m*/
public class Main {
  public static void main(String[] args) {
    Duration duration = Duration.between(LocalTime.MIDNIGHT,LocalTime.NOON);
    System.out.println(duration.getSeconds());
    duration = duration.plusSeconds(4000);
    System.out.println(duration.getSeconds());

  }
}

The code above generates the following result.