I don't know why I can't convert a String to a Date in Java Android. I got error when I try
The error :
W/System.err: java.text.ParseException: Unparseable date: "Fri Apr 30 00:12:13 GMT+02:00 2021"
My code :
String datestr = cursor.getString(cursor.getColumnIndex(UPDATED_AT)); // Fri Apr 30 00:12:13 GMT+02:00 2021
DateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.GERMANY);
myDate = dateFormat.parse(datestr);
Edit:
I'm up to date now (I think):
I convert all my Date to
OffsetDateTime currentDate = OffsetDateTime.now()
That gives me :
2021-04-30T02:14:49.067+02:00
Then If this date is a String and I want to convert it to OffsetDateTime :
String datestr = cursor.getString(cursor.getColumnIndex(UPDATED_AT)); // 2021-04-30T02:14:49.067+02:00
DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").withLocale( Locale.US );
OffsetDateTime myDate = OffsetDateTime.parse( datestr , f );