Java Date Time Java Java API
java.time.OffsetDateTime
public OffsetDateTime minusMonths(long months)
Returns a copy of this OffsetDateTime with the specified number of months subtracted, adjusting other fields if necessary.
package com.logicbig.example.offsetdatetime;import java.time.LocalDateTime;import java.time.OffsetDateTime;import java.time.ZoneOffset;public class MinusMonthsExample { public static void main (String... args) { OffsetDateTime d = OffsetDateTime.of(LocalDateTime.of(2016, 10, 3, 14, 30), ZoneOffset.of("-6")); System.out.println(d); OffsetDateTime offsetDateTime = d.minusMonths(4); System.out.println(offsetDateTime); OffsetDateTime offsetDateTime2 = d.minusMonths(400); System.out.println(offsetDateTime2); }}
2016-10-03T14:30-06:002016-06-03T14:30-06:001983-06-03T14:30-06:00
package com.logicbig.example.offsetdatetime;import java.time.LocalDateTime;import java.time.OffsetDateTime;import java.time.ZoneOffset;public class MinusMonthsExample2 { public static void main (String... args) { OffsetDateTime d = OffsetDateTime.of(LocalDateTime.of(2016, 10, 3, 14, 30), ZoneOffset.of("-6")); System.out.println(d); OffsetDateTime offsetDateTime = d.minusMonths(-4); System.out.println(offsetDateTime); OffsetDateTime offsetDateTime2 = d.minusMonths(-400); System.out.println(offsetDateTime2); }}
2016-10-03T14:30-06:002017-02-03T14:30-06:002050-02-03T14:30-06:00