Formatting a String date into a different format in Java

前端 未结 5 823
旧巷少年郎
旧巷少年郎 2020-12-20 05:50

I am trying to format a JSON which has a date key in the format:

date: \"2017-05-23T06:25:50\"

My current attempt i

5条回答
  •  难免孤独
    2020-12-20 06:37

    Use this code to format your `2017-05-23T06:25:50'

    String strDate = "2017-05-23T06:25:50";
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    Date convertedDate = new Date();
    try {
        convertedDate = dateFormat.parse(strDate);
        SimpleDateFormat sdfnewformat = new SimpleDateFormat("MMM dd yyyy");
        String finalDateString = sdfnewformat.format(convertedDate);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    

    The converted finalDateString set to your textView

提交回复
热议问题