Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
communitycreator
minusminutes
duration

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

minusMinutes() is an instance method of the Duration class that is used to subtract the specified duration in minutes from the Duration object.

The minusMinutes() method is defined in the Duration class. The Duration class is defined in the java.time package. To import the Duration class, check the following import statement.

import java.time.Duration;

Syntax


public Duration minusMinutes(long minutesToSubtract)

Parameters

  • long minutesToSubtract: The number of minutes to subtract. Can be positive or negative.

Return value

This method returns a new instance of the Duration class with the number of minutes subtracted.

Code

In the below code, we subtract 100 minutes from the baseDuration object with the help of the minusMinutes() method and print the new object to the console.

import java.time.Duration;
public class Main{
public static void main(String[] args) {
// setting up base duration of three days
Duration baseDuration = Duration.ofDays(3);
// minutes to be subtracted
int minutesToSubtract = 100;
// subtracting the minutes from base duration
Duration newDuration = baseDuration.minusMinutes(minutesToSubtract);
// printing
System.out.printf("%s - %s minutes = %s", baseDuration, minutesToSubtract, newDuration);
System.out.println();
}
}

RELATED TAGS

java
communitycreator
minusminutes
duration

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