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.
2
Answers
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 that marker is 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
: