Adjusts the specified temporal object to this Year object. This method returns a temporal object of the same type as of the input type.
package com.logicbig.example.year;
import java.time.*;
import java.time.temporal.Temporal;
public class AdjustIntoExample {
public static void main(String... args) {
Year y = Year.of(2011);
System.out.println(y);
adjust(y, LocalDate.now());
adjust(y, LocalDateTime.now());
adjust(y, OffsetDateTime.now());
adjust(y, ZonedDateTime.now());
adjust(y, YearMonth.now());
adjust(y, Year.now());
}
private static void adjust(Year y, Temporal t) {
Temporal t2 = y.adjustInto(t);
System.out.printf("%15s > %s > %s%n",
t.getClass().getSimpleName(),
t, t2);
}
}
Output
2011
LocalDate > 2017-05-01 > 2011-05-01
LocalDateTime > 2017-05-01T15:53:49.676 > 2011-05-01T15:53:49.676
OffsetDateTime > 2017-05-01T15:53:49.677-05:00 > 2011-05-01T15:53:49.677-05:00
ZonedDateTime > 2017-05-01T15:53:49.677-05:00[America/Chicago] > 2011-05-01T15:53:49.677-05:00[America/Chicago]
YearMonth > 2017-05 > 2011-05
Year > 2017 > 2011