I'm trying to format Instant
to String
with a specific format. Based on the question here Format Instant to String, I'm doing this -
DateTimeFormatter formatter = DateTimeFormatter
.ofPattern("YYYY-MM-DD'T'hh:mm'Z'")
.withZone(ZoneOffset.UTC);
// Fails for current time with error 'Field DayOfYear cannot be printed as the
// value 148 exceeds the maximum print width of 2'
LocalDateTime
.ofInstant(Instant.now(), ZoneOffset.UTC)
.format(DATE_TIME_FORMATTER);
// But works for smaller values of Instant
LocalDateTime
.ofInstant(Instant.ofEpochMilli(604800000), ZoneOffset.UTC)
.format(DATE_TIME_FORMATTER));
Any suggestions on why is this happening?
Thanks