Java.Text.Parseexception: Unparseable Date: Java.Text.Dateformat.Parse(Dateformat.Java:579)

java.text.ParseException: Unparseable date for hh:mm a

Found the problem thanks to @ArnaudDenoyelle. I checked SimpleDateFormat class, turns out 1 valued constructor calls 2 valued with defaul Locale:

public SimpleDateFormat(String pattern)
{
this(pattern, Locale.getDefault(Locale.Category.FORMAT));
}

AM/PM is seen as an error for my country, as it uses 24 hour system. As my phone and simple java application return different default Locale values, I was getting different results.

While it is not a solution, I used Locale.France to avoid the problem:

SimpleDateFormat formatting = new SimpleDateFormat(parseFormat, Locale.FRANCE);

java.text.ParseException: Unparseable date:

You can use this workaround for your problem.

But actually Shlublu is correct.

private static void parseTime(String dtStart) {
String time = dtStart.substring(0, dtStart.length() - 4);
System.out.println(time);
String timePick = dtStart.substring(dtStart.length() - 4, dtStart.length());
System.out.println(timePick);
if (timePick.equals("p.m.")) {
time += "PM";
} else if (timePick.equals("a.m.")) {
time += "AM";
}
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy hh:mm a", Locale.ENGLISH);
format.setTimeZone(TimeZone.getTimeZone("GMT"));
Date date = null;
try {
date = format.parse(time);
System.out.println("Date ->" + date);
} catch (Exception e) {
e.printStackTrace();
}
long ere = date.getTime() / 1000;
}

java.text.ParseException: Unparseable date on some devices only

It may be possible it can be affected by Symbols For am/pm in device default locale, so try to use locale as below to parse date it will help you.

   SimpleDateFormat formatGMT = new SimpleDateFormat("yyyy-MM-dd KK:mm:ss.SSS a", Locale.US);

formatGMT.setTimeZone(TimeZone.getTimeZone("GMT"));

try
{
date = formatGMT.parse("2016-09-06 05:18:06.023 PM");
}
catch (ParseException e)
{
Crashlytics.log(Log.ERROR, "DB Insertion error", e.getMessage().toString());
Crashlytics.logException(e);
e.printStackTrace();
}

java.text.ParseException: Unparseable date: 531772200000

This looks like a timestamp value, this will probably give you the date:

new Date(Long.parseLong("531772200000"));

which works out at Fri Nov 07 1986 18:30:00 GMT+0000



Related Topics



Leave a reply



Submit