When we call
parseJavaAndroid("2018-04-27T22:31:07.962-05:00")
from JVM it givesParseException
while a call from Emulator/Android Real device it works fine.When we change
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ", Locale.ENGLISH)
toSimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.ENGLISH)
in Android, it throws:IllegalArgumentException with message "Unknown pattern character 'X' method".
It works fine in JVM and gives
ParseException
in Emulator/Android Real device.
public static Date parseJavaAndroid(String fromDate){
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ", Locale.ENGLISH);
Date date=null;
try {
date = format.parse(fromDate);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
What should have to do then it works in both JVM and android real time device(minSdkVersion:19). I want pattern for "2018-04-27T22:31:07.962-05:00" which works on both Android as well as Java.
Note: The individual pattern is working, so Please don't suggest for individuals.