Skip to content

Instantly share code, notes, and snippets.

@khan-hasan
Created January 23, 2019 15:12
Show Gist options
  • Save khan-hasan/022c966710d8edaf19d88193deeba923 to your computer and use it in GitHub Desktop.
Save khan-hasan/022c966710d8edaf19d88193deeba923 to your computer and use it in GitHub Desktop.
Console.WriteLine("Enter a time value in the 24-hour time format (e.g. 19:00):");
var input = Console.ReadLine();
if (string.IsNullOrEmpty(input) || string.IsNullOrWhiteSpace(input))
Console.WriteLine("Invalid Time");
var lowTime = DateTime.Parse("00:00");
var highTime = DateTime.Parse("23:59");
var inputTime = DateTime.Parse(input);
try
{
if (inputTime >= lowTime && inputTime <= highTime)
Console.WriteLine("Ok");
else
Console.WriteLine("Invalid Time");
}
catch (Exception e)
{
Console.WriteLine("Generic Exception Handler: {0}", e.ToString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment