What is Duration.minusMinutes() in Java?

What is Duration.minusMinutes() in Java? Answer

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

}
What is Duration.minusMinutes() in Java? Review:

In our experience, we suggest you solve this What is Duration.minusMinutes() in Java? and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the What is Duration.minusMinutes() in Java?

Find on Educative

Conclusion:

I hope this What is Duration.minusMinutes() in Java? would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions

Leave a Reply

Your email address will not be published.