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
How to Redirect Multiple Types of Users to Their Respective Activities
Org.Apache.Http.Entity.Fileentity Is Deprecated in Android 6 (Marshmallow)
Will System.Currenttimemillis Always Return a Value ≫= Previous Calls
How to Fix Java.Lang.Unsupportedclassversionerror: Unsupported Major.Minor Version
Reading a Plain Text File in Java
Get Generic Type of Class At Runtime
What Is the Meaning of "This" in Java
How to Increment a Date by One Day in Java
Convert Inputstream to Byte Array in Java
How to Use an Existing Database With an Android Application
Android Update 17 Seems Incompatible With External Jars
Base 64 Encode and Decode Example Code
Technically What Is the Main Difference Between Oracle Jdk and Openjdk
How to Generate Random Integers Within a Specific Range in Java
Calling Awt Frame Methods from Subclass