Java Duration Class | ofMinutes() Method with Example

Duration Class ofMinutes() method: Here, we are going to learn about the ofMinutes() method of Duration Class with its syntax and example.
Submitted by Preeti Jain, on May 16, 2020

Duration Class ofMinutes() method

  • ofMinutes() method is available in java.time package.
  • ofMinutes() method is used to represent the given minutes value in this Duration.
  • ofMinutes() method is a static method, it is accessible with the class name and if we try to access the method with the class object then we will not get an error.
  • ofMinutes() method may throw an exception at the time of representing minutes.
    ArithmeticException: This exception may throw when the given minutes value exceeds the length of this Duration.

Syntax:

    public static Duration ofMinutes(long min_val);

Parameter(s):

  • long min_val – represents the number of minutes in value.

Return value:

The return type of this method is Duration, it returns the Duration that holds the value of the given minutes.

Example:

// Java program to demonstrate the example 
// of ofMinutes(long min_val) method of Duration

import java.time.*;

public class OfMinutesOfDuration {
    public static void main(String args[]) {
        long min_val = 10;

        // returns the Duration that holds the 
        // value of the given argument i.e. 
        // here we are representing
        // 10 minutes (10M) in this Duration du 
        Duration du = Duration.ofMinutes(min_val);

        // Display du
        System.out.println("Duration.ofMinutes(min_val): " + du);
    }
}

Output

Duration.ofMinutes(min_val): PT10M



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.