JDK8: unable to parse LocalTime

后端 未结 4 1304
北荒
北荒 2020-12-17 10:16

I managed to parse a String to a LocalDate object:

DateTimeFormatter f1=DateTimeFormatter.ofPattern(\"dd MM yyyy\");
LocalDate d=Lo         


        
4条回答
  •  温柔的废话
    2020-12-17 10:28

    If you use a specific format, according to API:

    The string must represent a valid time and is parsed using DateTimeFormatter.ISO_LOCAL_TIME.

    hh mm 
    

    for 24h must be

    HH mm
    

    or for 12h

    kk mm
    

    The handled formats must have this conditions:

    • Two digits for the hour-of-day. This is pre-padded by zero to ensure two digits.
    • A colon
    • Two digits for the minute-of-hour. This is pre-padded by zero to ensure two digits.
    • If the second-of-minute is not available then the format is complete.
    • A colon
    • Two digits for the second-of-minute. This is pre-padded by zero to ensure two digits.
    • If the nano-of-second is zero or not available then the format is complete.
    • A decimal point
    • One to nine digits for the nano-of-second. As many digits will be output as required.

提交回复
热议问题