Java Unparsable date

后端 未结 4 1501
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

    You need to provide as many S as you have in your date String. In this case, 7

    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'kk:mm:ss.SSSSSSSX");
    

    This is required because, otherwise, the DateFormat doesn't know where the milliseconds end and where the time zone starts.


    Note also, that

    2300963
    

    as a millisecond value means 2300 seconds and 963 milliseconds. Why do you have it that way? Why aren't those seconds part of the value in their corresponding position? When the DateFormat parses it, they will be added.

提交回复
热议问题