Java Date Time - Duration ofMillis(long millis) example








Duration ofMillis(long millis) creates a Duration representing a number of milliseconds.

The seconds and nanoseconds are extracted from the specified milliseconds.

Syntax

ofMillis has the following syntax.

public static Duration ofMillis(long millis)

Example

The following example shows how to use ofMillis.

import java.time.Duration;

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

The code above generates the following result.