Closed zefir-git closed 7 months ago
Instants doesn't contain a timezone information. You can use instant.atZone(ZoneId.systemDefault())
to get a TemporalAccessor with a timezone
@Joo200 I used instant.atZone(ZoneOffset.UTC).toLocalDateTime()
and that worked. This might be good to mention in the docs as Instant is TemporalAccessor
The requirement here isn't necessarily zone information, but support for time fields that you're using in your own format. Instant only supports limited fields, while you're requesting to use a format that uses years, months, hours, etc. A ZonedDateTime, OffsetDateTime, or LocalDateTime should all support what you need here
In theory, even a LocalDate should be able to fill-in the formatting for yyyy-MM-dd
just fine, but fail if you try to ask it for hour/min data, as that's something it cannot get.
I do believe it makes sene tho, that it throws some exception or log message when trying to use a temporal accesor that does not support all the fields you're requesting in the format
The documentation says inserting an instance of
TemporalAccessor
is possible usingFormatter.date
resolver. However, when usingDate#toInstant()
which returnsInstant
(which isTemporalAccessor
) the replacement is not done.No errors/warnings.
However, using the example from the docs (
LocalDateTime.now(ZoneId.systemDefault())
) works.