I want to achieve the converse of this, that is, I want to convert a string
with format hh:mm tt
to a TimeSpan
with zeroed seconds.
You can convert meridiem time to timespan and also timespan to meridiem time with date and only time using below code snipet...
TimeSpan ts = DateTime.Parse("8:00 PM").TimeOfDay;
DateTime dateWithTimeSlot = DateTime.Today+ ts;
//for getting MM/dd/yyyy hh:mm tt format
string dateWithMeridiemTimeSlot =
dateWithTimeSlot.ToString("MM/dd/yyyy hh:mm tt: ", CultureInfo.InvariantCulture);
Console.WriteLine("For getting MM/dd/yyyy hh:mm tt format: "+dateWithMeridiemTimeSlot);
//for getting only hh:mm tt format
string meridiemTimeSlot =
dateWithTimeSlot.ToString("hh:mm tt", CultureInfo.InvariantCulture);
Console.WriteLine("For getting only hh:mm tt format: " + meridiemTimeSlot);
Console.ReadLine();
Let's enjoy!
Thanks