
package com.logicbig.example.offsetdatetime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
public class WithYearExample {
public static void main(String... args) {
OffsetDateTime d = OffsetDateTime.of(2015, 10, 5, 15,
30, 10, 1000000, ZoneOffset.ofHours(-5));
System.out.println(d);
OffsetDateTime d2 = d.withYear(1300);
System.out.println(d2);
}
}
Output
2015-10-05T15:30:10.001-05:00
1300-10-05T15:30:10.001-05:00