Java Data Type How to - Get two hour Duration in Seconds








Question

We would like to know how to get two hour Duration in Seconds.

Answer

//from w w  w . ja va  2  s. com
import java.time.Duration;

public class Main {
  public static void main(String[] args) {

    long twoHoursInSeconds = Duration.ofHours(2).getSeconds();
    
    System.out.println(twoHoursInSeconds);
  }
}

The code above generates the following result.