I managed to parse a String
to a LocalDate
object:
DateTimeFormatter f1=DateTimeFormatter.ofPattern(\"dd MM yyyy\");
LocalDate d=Lo
In this case Unable to obtain LocalTime from TemporalAccessor
means it cannot determine the how far through the day the given string represents i.e. there is not enough information to construct a LocalTime
. Behind the scenes, the code looks something like this expanded Java 8 version (which gives a similar error):
DateTimeFormatter f2 = DateTimeFormatter.ofPattern("hh mm");
TemporalAccessor temporalAccessor = f2.parse("11 08");
LocalTime t = temporalAccessor.query(LocalTime::from);
System.out.println(t);
The LocalTime::from documentation says
The conversion uses the TemporalQueries.localTime() query, which relies on extracting the NANO_OF_DAY field.
Your error is telling you that the TemporalAccessor
only has two fields, neither of which is a NANO_OF_DAY
field. The minimum allowable patterns for retrieving a LocalTime
using a DateTimeFormatter
are:
DateTimeFormatter.ofPattern("ha");
DateTimeFormatter.ofPattern("Ka");
DateTimeFormatter.ofPattern("ah");
DateTimeFormatter.ofPattern("aK");
DateTimeFormatter.ofPattern("k");
DateTimeFormatter.ofPattern("H");
Your pattern must contain at least one of those strings to get a NANO_OF_DAY
field in the internal TemporalAccessor
from which a LocalTime
can be constructed.