What is Duration.toMinutes() in Java?

toMinutes() is an instance method of the Duration class that is used to get the number of minutes in the duration object. This method divides the number of seconds by 60 to return the total number of minutes in the duration.

The toMinutes() 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 long toMinutes()

Parameters

The method has no parameters.

Return value

The toMinutes() method returns the number of minutes in the duration.

Code

In the code below, we convert Duration class objects of different time units to minutes.

import java.time.Duration;
public class Main{
public static void main(String[] args) {
Duration durationInDays = Duration.ofDays(10);
System.out.println("10 days in minutes - " + durationInDays.toMinutes());
Duration durationInHours = Duration.ofHours(16);
System.out.println("16 hours in minutes - " + durationInHours.toMinutes());
}
}

Free Resources