Skip to content

Instantly share code, notes, and snippets.

@Ankit-Slnk
Created August 1, 2021 09:15
Show Gist options
  • Save Ankit-Slnk/8e77a2b456b2e02e33227c1a13d218df to your computer and use it in GitHub Desktop.
Save Ankit-Slnk/8e77a2b456b2e02e33227c1a13d218df to your computer and use it in GitHub Desktop.
Get hh:mm:ss from seconds
String getHMS(int seconds) {
if (seconds == null) return "";
final int minutes = (seconds / 60).truncate();
final int hours = (minutes / 60).truncate();
String secondsStr = (seconds % 60).toString().padLeft(2, '0');
String minutesStr = (minutes % 60).toString().padLeft(2, '0');
String hoursStr = (hours % 60).toString().padLeft(2, '0');
return "$hoursStr.$minutesStr.$secondsStr";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment