Java Date Time Java Java API
java.time.OffsetDateTime
public OffsetDateTime minusDays(long days)
This method subtracts the specified amount from the days field of the copy of this instance, if necessary adjusting the month and year fields to have a valid result.
package com.logicbig.example.offsetdatetime;import java.time.LocalDateTime;import java.time.OffsetDateTime;import java.time.ZoneOffset;public class MinusDaysExample {public static void main(String... args) { OffsetDateTime d = OffsetDateTime.of(LocalDateTime.of(2011, 10, 3, 14, 30), ZoneOffset.ofHours(-4)); System.out.println(d); OffsetDateTime d2 = d.minusDays(5); System.out.println(d2);}}
2011-10-03T14:30-04:002011-09-28T14:30-04:00
package com.logicbig.example.offsetdatetime;import java.time.LocalDateTime;import java.time.OffsetDateTime;import java.time.ZoneOffset;public class MinusDaysExample2 { public static void main (String... args) { OffsetDateTime d = OffsetDateTime.of(LocalDateTime.of(2011, 10, 3, 14, 30), ZoneOffset.ofHours(-4)); System.out.println(d); OffsetDateTime d2 = d.minusDays(5000); System.out.println(d2); }}
2011-10-03T14:30-04:001998-01-24T14:30-04:00