Java Date Time Java Java API
java.time.OffsetDateTime
public OffsetDateTime minusWeeks(long weeks)
Returns a copy of this OffsetDateTime with the specified number of weeks 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 MinusWeeksExample { public static void main (String... args) { OffsetDateTime d = OffsetDateTime.of(LocalDateTime.of(2015, 10, 29, 22, 33, 20), ZoneOffset.of("-4")); System.out.println(d); OffsetDateTime offsetDateTime = d.minusWeeks(10); System.out.println(offsetDateTime); OffsetDateTime offsetDateTime2 = d.minusWeeks(300); System.out.println(offsetDateTime2); OffsetDateTime offsetDateTime3 = d.minusWeeks(20000); System.out.println(offsetDateTime3); }}
2015-10-29T22:33:20-04:002015-08-20T22:33:20-04:002010-01-28T22:33:20-04:001632-07-08T22:33:20-04:00
package com.logicbig.example.offsetdatetime;import java.time.LocalDateTime;import java.time.OffsetDateTime;import java.time.ZoneOffset;public class MinusWeeksExample2 { public static void main (String... args) { OffsetDateTime d = OffsetDateTime.of(LocalDateTime.of(2015, 10, 29, 22, 33, 20), ZoneOffset.of("-4")); System.out.println(d); OffsetDateTime offsetDateTime = d.minusWeeks(-10); System.out.println(offsetDateTime); OffsetDateTime offsetDateTime2 = d.minusWeeks(-300); System.out.println(offsetDateTime2); OffsetDateTime offsetDateTime3 = d.minusWeeks(-20000); System.out.println(offsetDateTime3); }}
2015-10-29T22:33:20-04:002016-01-07T22:33:20-04:002021-07-29T22:33:20-04:002399-02-18T22:33:20-04:00