using System.Text.RegularExpressions;
using System.Globalization;
string intervalString = "02:30:00 PM";
string format = "hh\\:mm\\:ss tt";
CultureInfo culture = CultureInfo.InvariantCulture;
if (!string.IsNullOrEmpty(intervalString) && !string.IsNullOrEmpty(format))
if (TimeSpan.TryParseExact(intervalString, format, culture, out TimeSpan interval))
Console.WriteLine("'{0}' ({1}) --> {2}", intervalString, format, interval);
Console.WriteLine("Unable to parse '{0}' using format {1}", intervalString, format);
Console.WriteLine("Invalid time string or format provided.");