I'm trying to get milliseconds from a date but I got the exception
java.text.ParseException: Unparseable date: "Thu Jul 25 10:56:29 GMT+02:00 2019"
That's what I've done so far:
I took the date from a DatePicker with this pattern "EEE MMM dd HH:mm:ss zzz yyyy" and then passed to a method to get the milliseconds:
long milliDate = parseIso8601(dateTimeCalendar.getTime().toString());
private static long parseIso8601(String value) {
try {
return new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US).parse(value).getTime();
} catch (ParseException ignored) {
return 0;
}
}
I got the exception and it returns 0. I don't know what's wrong. Thanks
The problem in zone, zzz expect name of timezone, e.g. EST, GMT or other.
The correct pattern for your case:
EEE MMM dd HH:mm:ss 'GMT'XXX yyyy
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