Trusted answers to developer questions

What is Duration.toMinutes() in Java?

Get Started With Data Science

Learn the fundamentals of Data Science with this free course. Future-proof your career by adding Data Science skills to your toolkit — or prepare to land a job in AI, Machine Learning, or Data Analysis.

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());
}
}

RELATED TAGS

java
Did you find this helpful?