Home > Mobile >  Failed to parse date ["2022-02-21 13:26:59.213 00:00"]: Invalid time zone indicator '
Failed to parse date ["2022-02-21 13:26:59.213 00:00"]: Invalid time zone indicator '

Time:02-22

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 enter image description here

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?

I read this enter image description here

It even refers to the 0 offset: https://en.wikipedia.org/wiki/ISO_8601

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.

Source: patterns

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();
        }


    }
  • Related