What is Duration.plusMinutes() in Java?

The plusMinutes() method

plusMinutes() is an instance method of the Duration class that is used to add the specified duration in minutes to the Duration object.

How to import the Duration class

The plusMinutes() method is defined in the Duration class. The Duration class is defined in the java.time package.

To import the Duration class, use the import statement below.


import java.time.Duration;

Syntax


public Duration plusMinutes(long minutesToAdd)

Parameters

  • long minutesToAdd: The number of minutes to add. This parameter can be positive or negative.

Return value

The plusMinutes() method returns a new instance of the Duration class with the number of minutes added.

Code

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

import java.time.Duration;
public class Main{
public static void main(String[] args) {
Duration baseDuration = Duration.ofDays(3);
int minutesToAdd = 100;
Duration newDuration = baseDuration.plusMinutes(minutesToAdd);
System.out.printf("%s + %s minutes = %s", baseDuration, minutesToAdd, newDuration);
System.out.println();
}
}

Free Resources