Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart : parse date timezone gives UnimplementedError

I need to parse a date in the following format in my Flutter application (come from JSON) :

2019-05-17T15:03:22.472+0000

According to the documentation, I have to use Z to get the time zone (last 5 characters in RFC 822 format), so I use the following :

new DateFormat("y-M-d'T'H:m:s.SZ").parseStrict(json['startDate']);

But it fails with error :

FormatException: Characters remaining after date parsing in 2019-05-17T15:03:22.472+0000

Here is another test :

/// THIS WORKS
try {
    print(new DateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(DateTime.now()));
} catch (e) {
    print(e.toString());
}

/// THIS RETURNS `UnimplementedError` (as soon as I use a 'Z' or 'z') somewhere
try {
    print(new DateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(DateTime.now()));
} catch (e) {
    print(e.toString());
}

Is Z implemented ?

like image 619
Yann39 Avatar asked Dec 18 '22 17:12

Yann39


1 Answers

Sadly z and v patterns are not implemented.

Those won't be implemented until Dart DateTime's have time zone information

More info on this issue https://github.com/dart-lang/intl/issues/19

like image 137
Nuts Avatar answered Jan 13 '23 11:01

Nuts