Formatting date in java

前端 未结 5 1389
孤独总比滥情好
孤独总比滥情好 2021-01-26 07:04

I am trying to format date string ex. 2014-11-24T18:30:00.000Z to 2014-11-24 using this code below:

SimpleDateFormat dateFormat = new          


        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-26 07:30

    You have to parse the string first as a date and then format the date:

    SimpleDateFormat dateFormatP = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); 
    Date parsedDate = dateFormatP.parse(reqJsonObj.getString(FROM_DATE));
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 
    dateFormat.format(parsedDate );
    

提交回复
热议问题