Last Updated : 31 Oct, 2020
The
minusDays()method of
LocalDateclass in Java is used to subtract the number of specified day from this LocalDate and return a copy of LocalDate.For example, 2019-01-01 minus one day would result in 2018-12-31. This instance is immutable and unaffected by this method call.
Syntax:public LocalDate minusDays(long daysToSubtract)Parameters:
This method accepts a single parameter
daysToSubtractwhich represents the days to subtract, may be negative.
Return value:This method returns a
LocalDatebased on this date with the days subtracted, not null.
Exception:This method throws
DateTimeExceptionif the result exceeds the supported date range. Below programs illustrate the minusDays() method:
Program 1: Java
// Java program to demonstrate
// LocalDate.minusDays() method
import java.time.*;
public class GFG {
public static void main(String[] args)
{
// create a LocalDate object
LocalDate date
= LocalDate.parse("2018-11-13");
// print instance
System.out.println("LocalDate before"
+ " subtracting days: " + date);
// subtract 17 days
LocalDate returnvalue
= date.minusDays(17);
// print result
System.out.println("LocalDate after "
+ " subtracting days: " + returnvalue);
}
}
Output:
LocalDate before subtracting days: 2018-11-13 LocalDate after subtracting days: 2018-10-27Program 2: Java
// Java program to demonstrate
// LocalDate.minusDays() method
import java.time.*;
public class GFG {
public static void main(String[] args)
{
// create a LocalDate object
LocalDate date
= LocalDate.parse("2018-12-24");
// print instance
System.out.println("LocalDate before"
+ " subtracting days: " + date);
// subtract -15 days
LocalDate returnvalue
= date.minusDays(-15);
// print result
System.out.println("LocalDate after "
+ " subtracting days: " + returnvalue);
}
}
Output:
LocalDate before subtracting days: 2018-12-24 LocalDate after subtracting days: 2019-01-08Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalDate.html#minusDays(long)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4