Java.text.ParseException: Unmatched date

In my project I am trying to parse a date format like this "Mon Oct 20 00:00:00 GMT + 06: 30 2014" in dd-MM-yyyy, but I got the following error. I hope someone will solve this problem for me.

Thank,

10-20 13:03:01.390: W/System.err(23409): java.text.ParseException: Unparseable date: "Mon Oct 20 00:00:00 GMT+06:30 2014" (at offset 0)

      

parseDate.java

SimpleDateFormat formatter_date = new SimpleDateFormat("dd-MM-yyyy");
String sdate="Mon Oct 20 00:00:00 GMT+06:30 2014";
    try {
        Date _date= formatter_date.parse(sdate);
        holder.txtDate.setText(String.valueOf(_date));

    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

      

+3


source to share


2 answers


use this code



public static String parseTodaysDate(String time) {



    String inputPattern = "EEE MMM d HH:mm:ss zzz yyyy";

    String outputPattern = "dd-MM-yyyy";

    SimpleDateFormat inputFormat = new SimpleDateFormat(inputPattern);
    SimpleDateFormat outputFormat = new SimpleDateFormat(outputPattern);

    Date date = null;
    String str = null;

    try {
        date = inputFormat.parse(time);
        str = outputFormat.format(date);

        Log.i("mini", "Converted Date Today:" + str);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return str;
}

      

+8


source


Replace

SimpleDateFormat formatter_date = new SimpleDateFormat("dd-MM-yyyy");

      



from

SimpleDateFormat formatter_date = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);

      

+3


source







All Articles