I am consuming a C# webapi from an Android app using Retrofit. I have been getting an error:
Failed to parse date ["2022-02-21 12:10:18.043 00:00"]: Invalid time zone indicator ' '
The format I am using to return a date value from the C# dotnet api is:
"yyyy-MM-dd HH:mm:ss.fffzzz"
I found the formatting options on
But got the same error:
Caused by: java.text.ParseException: Failed to parse date ["2022-02-21 13:52:38.207 00:00"]: Invalid time zone indicator ' '
Has anybody run into this before?
It even refers to the 0 offset:
CodePudding user response:
According to your given date: 2022-02-21 12:10:18.043 00:00
your date format should look like yyyy-MM-dd HH:mm:ss.SSSZ
.
Sample code:
void parseDateExample() {
String dateToParse = "2022-02-21 12:10:18.043 00:00";
String dateFormat = "yyyy-MM-dd HH:mm:ss.SSSZ";
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, Locale.getDefault());
try {
Date date = sdf.parse(dateToParse);
Log.d("Mg-date", date.toString());
} catch (Exception e) {
e.printStackTrace();
}
}