timeToString static method
convert time (TimeOfDay to String)
Implementation
static String timeToString(
{required TimeOfDay time, String format = Format.fHHmmss}) {
int hour = time.hour;
String hourWithLeadingZero = leadingZero(hour);
String minuteWithLeadingZero = leadingZero(time.minute);
if (_equals(format, Format.fHHmmss)) {
String second = DateTimes.getCurrentDateTime(format: Format.fss);
return "$hourWithLeadingZero:$minuteWithLeadingZero:$second";
} else if (_equals(format, Format.fHHmm)) {
return "$hourWithLeadingZero:$minuteWithLeadingZero";
} else if (_equals(format, Format.fHHmma)) {
if (hour > 12) {
hour -= 12;
hourWithLeadingZero = leadingZero(hour);
}
if (hour == 0) {
hour = 12;
hourWithLeadingZero = leadingZero(hour);
}
return "$hourWithLeadingZero:$minuteWithLeadingZero ${time.period.name.toUpperCase()}";
} else {
return "";
}
}