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.
Duration
classThe 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;
public static Duration ofMinutes(long minutes)
long minutes
: The number of minutes. This parameter can be positive or negative.The method returns a Duration
object.
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);}}