Java Unparsable date

后端 未结 4 1511
Happy的楠姐
Happy的楠姐 2020-12-21 16:37

I have a string with the format: String dateString = \"2014-03-17T20:05:49.2300963Z\"

Trying this:

SimpleDateFormat df = new SimpleDateF         


        
4条回答
  •  情深已故
    2020-12-21 16:57

    tl;dr

    Instant.parse( "2014-03-17T20:05:49.2300963Z" )
    

    java.time

    You are using the troublesome old date-time classes, now legacy, supplanted by the java.time classes.

    Resolution

    • Milliseconds
      The old date-time classes were limited to milliseconds resolution, for up to three digits of decimal fraction.
    • Microseconds
      Your input has six digits of fractional second for microseconds.
    • Nanoseconds
      The java.time classes have a resolution of nanoseconds for up to nine digits of fractional seconds. More than enough for your microseconds.

    ISO 8601

    The ISO 8601 standard defines string formats to represent date-time values. You input complies with ISO 8601.

    The java.time classes use ISO 8601 formats by default when parsing and generating strings. So no need to specify a formatting pattern.

    Instant instant =
        Instant.parse( "2014-03-17T20:05:49.2300963Z" );
    

提交回复
热议问题