I've read many answers to this problem but no answer solves my problem
I am trying to parse this string :
"2013-10-07T23:21:00+01:00"
to a Date object with the simpledateformat :
"yyyy-MM-dd'T'HH:mm:ssZZZZZ"
but it keeps producing the error:
java.text.ParseException: Unparseable date: "" (at offset 0)
Note: I am trying this on Android, I'm a beginner.
Try with following code
public static Calendar parseDate(String dateTimeStr)
throws ParseException {
Calendar calendar = GregorianCalendar.getInstance();
String s = dateTimeStr.replace("Z", "+00:00");
try {
s = s.substring(0, 22) + s.substring(23);
} catch (IndexOutOfBoundsException e) {
throw new ParseException("Invalid length", 0);
}
Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").parse(s);
calendar.setTime(date);
return calendar;
}
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