Java Unparsable date

后端 未结 4 1508
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 17:03

    This works: SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'kk:mm:ss.SSSSSSS'Z'");

    1. It's safer to specify exactly how much precision you expect (say, for milliseconds in this case). It's odd to have 7 digits but if all your dates look like this, put 7 S.
    2. The X will parse a timezone of the sort -0800. So your string would have to look like 2014-03-17T20:05:49.2300963-0800 (or something similar). Treat the Z as a literal, like T.

    EDIT: Relevant to your partial seconds issue.

提交回复
热议问题