-1
final Object ret = task.getResult().get("ReturnExpiry");
returndate = String.valueOf(ret);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        try {
                            date = format.parse(returndate);
Log.e("date",String.valueOf(date));
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }

I am getting the error as

java.text.ParseException: Unparseable date: "Thu Jun 21 04:33:58 GMT+00:00 2018"
06-14 10:02:12.681 18943-18943/com.bodaty.samyata.samyata W/System.err:     at java.text.DateFormat.parse(DateFormat.java:362)

why I am getting error like this when I am trying to parse .... if I use code as below my app is crashing with parse error.....can anyone help me please

java.util.Date dt = new java.util.Date(returndate);
Vidhi Dave
  • 5,614
  • 2
  • 33
  • 55
Swapna
  • 127
  • 1
  • 10
  • is your _"yyyy-MM-dd HH:mm:ss"_ is correct? make sure this is the format that you are getting in `returndate` or just post the date which you are passing.. i will check – Vidhi Dave Jun 14 '18 at 10:11
  • your date format does not match your date. Read the `SimpleDateFormat` documentation to build pattern for your date – Vladyslav Matviienko Jun 14 '18 at 10:52

1 Answers1

0

Your data doesn't match your pattern. update your pattern like this

 SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);
        Date date = null;
        try{
            date  = sdf.parse("Thu Jun 21 04:33:58 GMT+00:00 2018");
        }catch (Exception e){ e.printStackTrace(); }
        System.out.println("check..." + date;

Hope it will solve your problem

Sandeep Parish
  • 1,888
  • 2
  • 9
  • 20