I am working on a time sheet application where I want the user to be able to enter time in TextBoxes, for example: 8 or 8:00 a or the like, as you can in Excel.
Now, if you enter a date in a TextBox and then use DateTime.TryParse, you can enter it in several formats (January 31, 2007, January 31, 2007, January 31, 2007, January 31, 2007).), And .NET will figure this out and turn it into a DateTime.
But when I use DateTime.TryParse for a string like "8 a" or "8:00 a", she does not understand it.
I know I can use ParseExact, but I wonder if there is a more flexible solution. I want .NET to get 8: 00a from "8 a" or "8:00 a" and leave the default date component 1/1/0001.
source share