0

It's my first question, but I try all day to find error:

I use simple code for parse DateTime from string:

DateTimeFormatter dateTimeFormatter=DateTimeFormatter.ofPattern ("yyyy-MM-dd hh:mm");
LocalDateTime start = LocalDateTime.parse("2019-12-01 10:00", dateTimeFormatter);

and got error:

Text '2019-12-01 10:00' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {HourOfAmPm=10, MinuteOfHour=0},ISO resolved to 2019-12-01 of type java.time.format.Parsed

where is my mistake?

amer
  • 1,528
  • 1
  • 14
  • 22
Eni
  • 1
  • I know the error message is long and looks intractable at first. Try. Does this bit look right? `HourOfAmPm=10`? – Ole V.V. Dec 27 '19 at 14:57

1 Answers1

3

Use HH (hour-of-day).

DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
amer
  • 1,528
  • 1
  • 14
  • 22
  • I really can't figure out where the error here – Eni Dec 27 '19 at 15:01
  • My bad , try to use HH insted of hh. – amer Dec 27 '19 at 15:01
  • I tried using HH, but the error is the same – Eni Dec 27 '19 at 15:03
  • 2
    @Eni, that can’t be. Please quote the (new) error message that you get when trying with uppercase `HH` instead of lowercase `hh`. When I paste the line from this answer into your code from the question, I get `start` equal to `2019-12-01T10:00` as expected. – Ole V.V. Dec 27 '19 at 15:06
  • friends, thank you for your quick help. The "yyyy-MM-dd HH:mm" works. This is all my fault for my inattention. – Eni Dec 30 '19 at 08:00