Java Date Time Java Java API
java.time.LocalDate
public LocalDate minusMonths(long monthsToSubtract)
This method subtracts the specified amount from the months field (adjusting other fields if necessary) and returns the new instance of LocalDate.
package com.logicbig.example.localdate;import java.time.LocalDate;import java.time.Month;public class MinusMonthsExample { public static void main (String... args) { LocalDate d = LocalDate.of(2016, Month.MARCH, 1); LocalDate localDate = d.minusMonths(20); System.out.println(localDate); }}
2014-07-01
package com.logicbig.example.localdate;import java.time.LocalDate;import java.time.Month;public class MinusMonthsExample2 { public static void main (String... args) { LocalDate d = LocalDate.of(2016, Month.MARCH, 31); LocalDate localDate = d.minusMonths(1); System.out.println(localDate); }}
2016-02-29
package com.logicbig.example.localdate;import java.time.LocalDate;import java.time.Month;public class MinusMonthsExample3 { public static void main (String... args) { LocalDate d = LocalDate.of(2016, Month.FEBRUARY, 29); LocalDate localDate = d.minusMonths(1); System.out.println(localDate); }}
2016-01-29