Last active
February 14, 2016 14:51
-
-
Save saifullah-azmi/7cc413648d964f2dc3a9 to your computer and use it in GitHub Desktop.
C# code to convert given whole numbers of seconds to hh:mm:ss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class SecondsToTime { | |
public static int Main() { | |
double totalSeconds; | |
Console.Write("Please enter the number of seconds: "); | |
string userInput = Console.ReadLine(); | |
while (!double.TryParse(userInput, out totalSeconds)) { | |
if (userInput.Equals("quit")) { | |
Console.WriteLine("Exiting the programme."); | |
Environment.Exit(0); | |
} else { | |
Console.WriteLine("Invalid Input. Please enter a whole number"); | |
userInput = Console.ReadLine(); | |
} | |
} | |
TimeSpan t = TimeSpan.FromSeconds(totalSeconds); | |
string time = t.ToString(@"hh\h\:mm\m\:ss\s"); | |
Console.Write(totalSeconds + " seconds = " + time); | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment