Java Date Time - Duration ofHours(long hours) example








Duration ofHours(long hours) creates a Duration representing a number of standard hours.

Syntax

ofHours has the following syntax.

public static Duration ofHours(long hours)

Example

The following example shows how to use ofHours.

import java.time.Duration;

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

The code above generates the following result.