Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
communitycreator

What is Duration.toMinutesPart() 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.

toMinutesPart() is an instance method of the Duration class, which is used to obtain the number of minutes part in the Duration object. The number of minutes part is calculated by taking the modulus of the value that is returned by the toMinutes() method with the value 60. This is based on the traditional 60-minute definition of an hour. This method was introduced in Java version 9.

The toMinutesPart method is defined in the Duration class. The Duration class is defined in the java.time package. To import the Duration class, we check the following import statement:

import java.time.Duration;

Syntax


public int toMinutesPart()

Parameters

This method has no parameters.

Return value

This method returns the number of minutes part in the Duration object.

Code

import java.time.Duration;
public class Main {
public static void main(String[] args) {
Duration duration = Duration.ofSeconds(143234);
long numOfMinutesPart = duration.toMinutesPart();
System.out.printf("Number of mintues part in %s is %s", duration, numOfMinutesPart);
}
}
Implementation of the "toMinutesPart" method

Explanation

  • Line 1: We import the Duration class.
  • Line 6: We define a Duration object, using the ofSeconds() method.
  • Line 8: We get the number of minutes part in the Duration object, using the toMinutesPart() method.
  • Line 10: We print the Duration object and the number of minutes part that we obtained in line 8.

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.

Keep Exploring