Skip to content

Instantly share code, notes, and snippets.

@codejockie
Created October 19, 2017 14:34
Show Gist options
  • Save codejockie/1cbc48ff93e21fbd51df86e41d610af9 to your computer and use it in GitHub Desktop.
Save codejockie/1cbc48ff93e21fbd51df86e41d610af9 to your computer and use it in GitHub Desktop.
Time converter
using System;
public class Program {
static void Main() {
Console.WriteLine(timeFormatter(54000));
}
static string timeFormatter(int seconds) {
float h = seconds / 3600;
float m = (seconds % 3600) / 60;
float s = seconds % 60;
var time = "";
if (h < 10) {
time += "0" + h + ":";
} else {
time += h + ":";
}
if (m < 10) {
time += "0" + m + ":";
} else {
time += m + ":";
}
if (s < 10) {
time += "0" + s;
} else {
time += s;
}
return time;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment