Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
communitycreator

What is Duration.toMinutes() in Java?

abhilash

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

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
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring