timeFormat static method

String timeFormat(
  1. num time
)

It takes an integer, and returns a string

Args: time (int): The time in seconds.

Returns: A string with the format "hh:mm:ss"

Implementation

static String timeFormat(num time) {
  final num h = time ~/ 3600;
  final num m = (time - h * 3600) ~/ 60;
  final num s = time - (h * 3600) - (m * 60);
  final String hourLeft = h.toString().length < 2 ? "0$h" : h.toString();
  final String minuteLeft = m.toString().length < 2 ? "0$m" : m.toString();
  final String secondsLeft = s.toString().length < 2 ? "0$s" : s.toString();
  if (hourLeft == "00") {
    return "$minuteLeft:$secondsLeft";
  }

  return "$hourLeft:$minuteLeft:$secondsLeft";
}