How to parse threeten DateTIme

1.2k views Asked by At

I am trying to parse this DateTime:

DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder()
                    .appendPattern("dd/MM/yyyy hh:mm:ss")
                    .parseDefaulting(ChronoField.SECOND_OF_MINUTE, 0)
                    .parseDefaulting(ChronoField.MILLI_OF_SECOND, 0)
                    .toFormatter();

            String ultimaAtualizacaoTexto = "17/12/2016 01:41:43";

            LocalDateTime ultimaAtualizacaoDateTime =
                    LocalDateTime.parse(ultimaAtualizacaoTexto, dateTimeFormatter);

But I am getting this error:

DateTimeParseException: Text '17/12/2016 01:41:43' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: DateTimeBuilder[fields={MilliOfSecond=0, MinuteOfHour=41, MicroOfSecond=0, NanoOfSecond=0, HourOfAmPm=1, SecondOfMinute=43}, ISO, null, 2016-12-17, null], type org.threeten.bp.format.DateTimeBuilder

I am not sure what is going on... It should totally work!

Any help with this? Thanks anyway!

1

There are 1 answers

1
Leandro Borges Ferreira On BEST ANSWER

So... I had to change "dd/MM/yyyy hh:mm:ss" to "dd/MM/yyyy HH:mm:ss"

Because hh is only for 12 am/pm hours. HH is for 24h.