Java Date Time Java Java API
java.time.LocalDate
public LocalDate minusYears(long yearsToSubtract)
This method subtracts the specified amount from the years field (adjusting other fields if necessary).
package com.logicbig.example.localdate;import java.time.LocalDate;import java.time.Month;public class MinusYearsExample { public static void main (String... args) { LocalDate d = LocalDate.of(2016, Month.DECEMBER, 1); LocalDate localDate = d.minusYears(10); System.out.println(localDate); }}
2006-12-01
package com.logicbig.example.localdate;import java.time.LocalDate;import java.time.Month;public class MinusYearsExample2 { public static void main (String... args) { //leap year LocalDate d = LocalDate.of(2000, Month.FEBRUARY, 29); LocalDate localDate = d.minusYears(1); System.out.println(localDate); }}
1999-02-28
package com.logicbig.example.localdate;import java.time.LocalDate;import java.time.Month;public class MinusYearsExample3 { public static void main (String... args) { LocalDate d = LocalDate.of(2001, Month.FEBRUARY, 28); LocalDate localDate = d.minusYears(1); System.out.println(localDate); }}
2000-02-28