toString method Null safety
override
Returns a string representation of this Duration.
Returns a string with hours, minutes, seconds, and microseconds, in the
following format: H:MM:SS.mmmmmm
. For example,
var d = Duration(days: 1, hours: 1, minutes: 33, microseconds: 500);
d.toString(); // "25:33:00.000500"
d = Duration(days: 0, hours: 1, minutes: 10, microseconds: 500);
d.toString(); // "1:10:00.000500"
Implementation
String toString() {
var microseconds = inMicroseconds;
var hours = microseconds ~/ microsecondsPerHour;
microseconds = microseconds.remainder(microsecondsPerHour);
if (microseconds < 0) microseconds = -microseconds;
var minutes = microseconds ~/ microsecondsPerMinute;
microseconds = microseconds.remainder(microsecondsPerMinute);
var minutesPadding = minutes < 10 ? "0" : "";
var seconds = microseconds ~/ microsecondsPerSecond;
microseconds = microseconds.remainder(microsecondsPerSecond);
var secondsPadding = seconds < 10 ? "0" : "";
var paddedMicroseconds = microseconds.toString().padLeft(6, "0");
return "$hours:"
"$minutesPadding$minutes:"
"$secondsPadding$seconds.$paddedMicroseconds";
}