✅ Converting Time???
internal string CheckTimeFormat(string input, string message)
{
string format = @"hh\:mm\:ss";
CultureInfo culture = CultureInfo.InvariantCulture;
TimeSpanStyles style = TimeSpanStyles.None;
TimeSpan result;
try
{
while (!TimeSpan.TryParseExact(input, format, culture, style, out result))
{
Console.WriteLine("Invalid Time Input! Try Again!");
Console.Write(message);
input = Console.ReadLine();
}
return result.ToString();
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
return null;
}
}
internal string CheckTimeFormat(string input, string message)
{
string format = @"hh\:mm\:ss";
CultureInfo culture = CultureInfo.InvariantCulture;
TimeSpanStyles style = TimeSpanStyles.None;
TimeSpan result;
try
{
while (!TimeSpan.TryParseExact(input, format, culture, style, out result))
{
Console.WriteLine("Invalid Time Input! Try Again!");
Console.Write(message);
input = Console.ReadLine();
}
return result.ToString();
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
return null;
}
}
14:45
or 02:45 PM
and it still convert appropriately?1 Reply
internal string CheckTimeFormat(string input, string message)
{
string format = "hhmm";
CultureInfo culture = CultureInfo.InvariantCulture;
TimeSpanStyles style = TimeSpanStyles.None;
TimeSpan result;
try
{
while (!TimeSpan.TryParseExact(input, format, culture, style, out result))
{
Console.WriteLine("Invalid Time Input! Try Again!");
Console.Write(message);
input = Console.ReadLine();
}
return result.ToString();
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
return null;
}
}
internal string CheckTimeFormat(string input, string message)
{
string format = "hhmm";
CultureInfo culture = CultureInfo.InvariantCulture;
TimeSpanStyles style = TimeSpanStyles.None;
TimeSpan result;
try
{
while (!TimeSpan.TryParseExact(input, format, culture, style, out result))
{
Console.WriteLine("Invalid Time Input! Try Again!");
Console.Write(message);
input = Console.ReadLine();
}
return result.ToString();
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
return null;
}
}
hhmm
format instead to make it easier