timeOfDayToString static method

String timeOfDayToString({
  1. required TimeOfDay time,
  2. bool hasSeconds = true,
  3. String format = Format.fHHmmss,
})

convert time (TimeOfDay to String)

Implementation

static String timeOfDayToString(
    {required TimeOfDay time,
    bool hasSeconds = true,
    String format = Format.fHHmmss}) {
  int hour = time.hour;
  String hourWithLeadingZero = leadingZero(hour);
  String minuteWithLeadingZero = leadingZero(time.minute);

  if (hasSeconds) {
    String second = DateTimes.getCurrentDateTime(format: Format.fss);
    return "$hourWithLeadingZero:$minuteWithLeadingZero:$second";
  } else {
    return "$hourWithLeadingZero:$minuteWithLeadingZero:00";
  }
}