I am using the following to parse a string to date. However I get an Unparseable date exception. This is the code
String dateString="2018-09-20T11:44:48.000Z";//MYSQL timestamp from server
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy'T'HH:mm:ss.S'Z'");
Date convertedDate = new Date();
try {
convertedDate = dateFormat.parse(dateString); //error here
textTime.setReferenceTime(convertedDate.getTime());
} catch (ParseException e) {
e.printStackTrace();
}
Instant,LocalDateTimeorTimestamp, whichever works. (2) Consider avoiding theSimpleDateFormatclass, it’s long outdated and notoriously troublesome. If java.time, the modern Java date and time API, isn’t built into your Android version, consider the ThreeTenABP library, the backport of java.time for Android.Zin the date string as a literal (in single quotes). It’s a UTC offset and needs to be parsed as such. OtherwiseSimpleDateFormatwill use the JVM’s time zone, leading to an incorrect point in time.