Android parse String to Date - unknown pattern character 'X'

前端 未结 13 1061
耶瑟儿~
耶瑟儿~ 2021-01-31 07:32

I have Service fetch date string from web and then I want to pare it to Date object. But somehow application crashes. This is my string that I\'m parsi

13条回答
  •  时光取名叫无心
    2021-01-31 07:57

    Use a SimpleDateFormat to produce a properly formatted String output:

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    
    String formattedNow = simpleDateFormat.format(new Date(System.currentTimeMillis()));
    

    Output : 2018-02-27T07:36:47.686Z

提交回复
热议问题