Getting error java.text.ParseException: Unparseable date: (at offset 0) even if the Simple date format and string value are identical

后端 未结 3 1303
Happy的楠姐
Happy的楠姐 2020-11-27 08:44

I\'m always getting the parse exception even if the format to check and the string value are same. Here is the code:

String format = \"EEE MMM dd HH:mm:ss z          


        
3条回答
  •  不知归路
    2020-11-27 09:19

    Here is the code of dateformatter which will hep you to convert your date into any time format.

    public void setDate(String date) {
                dateInput = (TextView) itemView.findViewById(R.id.dateText);
                DateFormat inputFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
                try {
                    dateData = inputFormat.parse(date);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                DateFormat outputFormat = new SimpleDateFormat("pur your desirable format");
                String outputString = outputFormat.format(dateData);
                dateInput.setText(outputString);
            }
    

提交回复
热议问题