Java Date Time Java Java API
java.time.OffsetDateTime
public OffsetDateTime minusYears(long years)
Returns a copy of this OffsetDateTime with the specified number of years subtracted.
package com.logicbig.example.offsetdatetime;import java.time.LocalDateTime;import java.time.OffsetDateTime;import java.time.ZoneOffset;public class MinusYearsExample { public static void main (String... args) { OffsetDateTime d = OffsetDateTime.of(LocalDateTime.of(2012, 5, 19, 20, 24, 10), ZoneOffset.of("-6")); System.out.println(d); OffsetDateTime offsetDateTime = d.minusYears(14); System.out.println(offsetDateTime); OffsetDateTime offsetDateTime2 = d.minusYears(305); System.out.println(offsetDateTime2); }}
2012-05-19T20:24:10-06:001998-05-19T20:24:10-06:001707-05-19T20:24:10-06:00
package com.logicbig.example.offsetdatetime;import java.time.LocalDateTime;import java.time.OffsetDateTime;import java.time.ZoneOffset;public class MinusYearsExample2 { public static void main (String... args) { OffsetDateTime d = OffsetDateTime.of(LocalDateTime.of(2012, 5, 19, 20, 24, 10), ZoneOffset.of("-6")); System.out.println(d); OffsetDateTime offsetDateTime = d.minusYears(-14); System.out.println(offsetDateTime); OffsetDateTime offsetDateTime2 = d.minusYears(-305); System.out.println(offsetDateTime2); }}
2012-05-19T20:24:10-06:002026-05-19T20:24:10-06:002317-05-19T20:24:10-06:00