Date and Time

How to adding minutes with plusMinutes in Java LocalDateTime

Table of Contents

Program

import java.time.LocalDateTime;
import java.text.ParseException;
public class Minutes
{
    public static void main(String[] args) throws ParseException 
    {
        LocalDateTime dt1 = LocalDateTime.parse("2020-01-11T10:15:30");
        LocalDateTime dt2=dt1.plusMinutes(60);
        System.out.println("After 60 minutes added: "+dt2);
    }
}

Output

After 60 minutes added: 2018-01-11T11:15:30

Description

public LocalDateTime plusMinutes​(long minutes)

Returns a copy of this LocalDateTime with the specified number of minutes added.
This instance is immutable and unaffected by this method call.

Parameters:

minutes – the minutes to add, may be negative

Returns:

a LocalDateTime based on this date-time with the minutes added, not null

Throws:

DateTimeException – if the result exceeds the supported date range