I have a collection of data in my database, time and description, select String as the data type of my time, my question is how can I format time data in this format "HH: MM AM / PM"
The time is "4:45 PM", I want to format it in this format "04:45 PM" in C #, but I do not know how this can be formatted.
here is my code:
var str = touritinerary.Model.Time;
var timePattern = "h:mm";
DateTime finalizeTime;
if (DateTime.TryParseExact(str, timePattern, null, DateTimeStyles.None, out finalizeTime))
{
Console.WriteLine("Time: {1:hh:mm }", finalizeTime);
}
I want 16:45 formatted at 16:45
source
share