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);
}
}
Output
2011-10-03T14:30-04:00
2011-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);
}
}
Output
2011-10-03T14:30-04:00
1998-01-24T14:30-04:00