Java Date Time Java Java API
Class:
java.time.LocalDate
Method:
public LocalDate plusDays(long daysToAdd)
This method adds the provided long amount to the days field adjusting the month and year fields if necessary. The original instance is not changed.
The provided value can be negative, in that days are subtracted instead of being added.
Examples
package com.logicbig.example.localdate;
import java.time.LocalDate; import java.time.Month;
public class PlusDaysExample {
public static void main (String... args) {
LocalDate d = LocalDate.of(1980, Month.APRIL, 20); LocalDate d2 = d.plusDays(400); System.out.println(d2);
LocalDate d3 = d.plusDays(-400); System.out.println(d3); } }
Output1981-05-25 1979-03-17
package com.logicbig.example.localdate;
import java.time.LocalDate; import java.time.Month;
public class PlusDaysExample2 {
public static void main (String... args) {
LocalDate d = LocalDate.of(1980, Month.APRIL, 20); LocalDate d2 = d.plusDays(Long.MIN_VALUE); System.out.println(d2); } }
Output
|