What is Duration.ofMinutes() in Java?
Introduction
ofMinutes() is a Duration class that is used to get a Duration class instance that corresponds to the number of standard minutes.
The seconds are determined with the standard definition of a minute, which is 60 seconds.
Import the Duration class
The ofMinutes() method is defined in the Duration class. The Duration class is defined in the java.time package.
To import the Duration class, use the following import statement:
import java.time.Duration;
Syntax
public static Duration ofMinutes(long minutes)
Parameters
long minutes: The number of minutes. This parameter can be positive or negative.
Return value
The method returns a Duration object.
Code
In the code below, we create two Duration class objects with a positive and negative number of minutes. Then, we print the objects to the console.
import java.time.Duration;public class Main{public static void main(String[] args) {Duration positiveMinutes = Duration.ofMinutes(5);System.out.println("Positive Minutes - " + positiveMinutes);Duration negativeMinutes = Duration.ofMinutes(-5);System.out.println("Negative Minutes - " + negativeMinutes);}}