I'm getting the issue when converting string to TimeOfDay
. It was working before but now I am getting the issue.
try {
final format = DateFormat.jm(); //"6:00 AM"
TimeOfDay day = TimeOfDay.fromDateTime(format.parse("6:00"));
} catch(ex) {
PLPrint(name: "CheckTest",value: "${ex.toString()}");
}
I have tried the format for parsing string:
1: 6:00 - FormatException: Trying to read from 6:00 at 5
2: 6:00 AM - FormatException: Trying to read from 6:00 AM at 5
3: 6:00:00 - FormatException: Trying to read from 6:00:00 at 5
4: 6:00:00 AM - FormatException: Trying to read from 6:00:00 AM at 5
5: 16:00 - FormatException: Trying to read from 16:00 at 6
6: 16:00:00 - FormatException: Trying to read from 16:00:00 at 6
I have tried almost all the formats but still getting the Format issue.
The
DateFormat
jm
skeleton uses a locale-dependent format and therefore can vary. In the default locale (which I think is default to U.S. English locale), that format includes an AM/PM marker, and as of 2023 that marker is now separated with a Unicode non-breaking space (specifically U+202F):If you want
jm
to accept other types of whitespace, useDateFormat.parseLoose
instead ofDateFormat.parse
:From empirical testing, the change to use a non-breaking space seems to have been picked up by
package:intl
in 0.18.1, so you also could consider rolling back to 0.18.0 as another workaround.Also see https://github.com/dart-lang/i18n/issues/743.