I have a string called TheUserTime that looks like this:
string TheUserTime = "12.12.2011.16.22"; //16 is the hour in 24-hour format and 22 is the minutes
I want to generate a DateTime from this by splitting the string in a array of ints (what happens when it’s 0?) and composing the date object.
What’s the best way to do this?
Thanks.
You should use
DateTime.ParseExactorDateTime.TryParseExactwith a custom format string instead.ParseExact:TryParseExact:Using
TryParseExactavoids a possible exception if the parse fails, though is such a case thedtvariable will have the default value forDateTime.