15 lines
619 B
Dart
15 lines
619 B
Dart
String formatTime(int seconds) {
|
|
Duration duration = Duration(seconds: seconds);
|
|
String formattedTime = '';
|
|
String twoDigits(int n) => n.toString().padLeft(2, "0");
|
|
String days = duration.inDays.toString();
|
|
String hours = twoDigits(duration.inHours.remainder(24));
|
|
String minutes = twoDigits(duration.inMinutes.remainder(60));
|
|
String formattedSeconds = twoDigits(duration.inSeconds.remainder(60));
|
|
if (duration.inDays != 0) formattedTime += '$days:';
|
|
if (duration.inHours != 0) formattedTime += '$hours:';
|
|
formattedTime += '$minutes:';
|
|
formattedTime += formattedSeconds;
|
|
return formattedTime;
|
|
}
|