Returns an ISO-8601 full-precision extended format representation.
The format is yyyy-MM-ddTHH:mm:ss.sssZ for UTC time, and
yyyy-MM-ddTHH:mm:ss.sss (no trailing "Z") for local/non-UTC time,
where:
-
yyyyis a, possibly negative, four digit representation of the year, if the year is in the range -9999 to 9999, otherwise it is a signed six digit representation of the year. MMis the month in the range 01 to 12,ddis the day of the month in the range 01 to 31,HHare hours in the range 00 to 23,mmare minutes in the range 00 to 59,ssare seconds in the range 00 to 59 (no leap seconds), andsssare milliseconds in the range 000 to 999.
The resulting string can be parsed back using parse.
Source
String toIso8601String() {
String y = (year >= -9999 && year <= 9999) ? _fourDigits(year)
: _sixDigits(year);
String m = _twoDigits(month);
String d = _twoDigits(day);
String h = _twoDigits(hour);
String min = _twoDigits(minute);
String sec = _twoDigits(second);
String ms = _threeDigits(millisecond);
if (isUtc) {
return "$y-$m-${d}T$h:$min:$sec.${ms}Z";
} else {
return "$y-$m-${d}T$h:$min:$sec.$ms";
}
}