In my project, I am trying to parse date format like this "Mon Oct 20 00:00:00 GMT+06:30 2014" to dd-MM-yyyy but I got the following error. I am hoping someone to solve me this problem.
Thanks,
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();
}
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;
}
Replace
SimpleDateFormat formatter_date = new SimpleDateFormat("dd-MM-yyyy");
with
SimpleDateFormat formatter_date = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With