I am trying to convert string to date inside Asynctask by parsing json string. I referred this link: How to convert "Mon Jun 18 00:00:00 IST 2012" to 18/06/2012?
//String dateStr = "Mon Jun 18 00:00:00 IST 2012";
changedDate = jsonObjectMain.getString("date");
DateFormat formatter = new SimpleDateFormat("E MMM dd HH:mm:ss Z yyyy");
Date date = (Date)formatter.parse(changedDate);
System.out.println(date);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
String formatedDate = cal.get(Calendar.DATE) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.YEAR);
System.out.println("formatedDate : " + formatedDate);
When I run this code in android studio, it gives me below exception:
04-14 12:35:53.363 22963-22963/com.trial W/System.err: java.text.ParseException: Unparseable date: "Mon Jun 18 00:00:00 IST 2012" (at offset 20) 04-14 12:35:53.367 22963-22963/com.trial W/System.err: at java.text.DateFormat.parse(DateFormat.java:579) 04-14 12:35:53.367 22963-22963/com.trial W/System.err: at com.trial.Activity.StartActivity.onClick(StartActivity.java:124) 04-14 12:35:53.367 22963-22963/com.trial W/System.err: at android.view.View.performClick(View.java:5210) 04-14 12:35:53.367 22963-22963/com.trial W/System.err: at android.view.View$PerformClick.run(View.java:21183) 04-14 12:35:53.367 22963-22963/com.trial W/System.err: at android.os.Handler.handleCallback(Handler.java:739) 04-14 12:35:53.367 22963-22963/com.trial W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95) 04-14 12:35:53.367 22963-22963/com.trial W/System.err: at android.os.Looper.loop(Looper.java:148) 04-14 12:35:53.367 22963-22963/com.trial W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5438) 04-14 12:35:53.367 22963-22963/com.trial W/System.err: at java.lang.reflect.Method.invoke(Native Method) 04-14 12:35:53.367 22963-22963/com.trialW/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:762) 04-14 12:35:53.367 22963-22963/com.trial W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
But when i run same code in eclipse by creating simple program, it runs very well.
I was wondered, I don't know, why is this happen. So, i checked same code in another Activity on button click but not worked.
Thank you. Any help will be appreciated.