© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
1 reply
Mek

✅ 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;
    }
}
How can I edit this so that I can either edit
14:45
14:45
or
02:45 PM
02:45 PM
and it still convert appropriately?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Converting project
C#CC# / help
3y ago
NATS Client timeouts all the time
C#CC# / help
4y ago
Help converting indicators...
C#CC# / help
3y ago
WPF Video Editor program | Help with the (Timeline/TimeMarks)
C#CC# / help
11mo ago