Java Date Time - Duration ofSeconds(long seconds) example








Duration ofSeconds(long seconds) creates a Duration representing a number of seconds. The nanosecond in second field is set to zero.

Syntax

ofSeconds has the following syntax.

public static Duration ofSeconds(long seconds)

Example

The following example shows how to use ofSeconds.

import java.time.Duration;

public class Main {
  public static void main(String[] args) {
    Duration duration = Duration.ofSeconds(10);
    System.out.println(duration);
  }
}

The code above generates the following result.