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;
public long toMinutes()
The method has no parameters.
The toMinutes()
method returns the number of minutes in the duration.
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());}}