Search code examples
c#stringdatetimedate-conversion

Converting Unusual DateTime String to DateTime Object


I'm working with a log file that is giving me a date string that looks like so:

09/Feb/2012:00:38:48

I've been looking at different pages online about converting dates such as the MSDN site, but none of them show a date quite like this one.

Do I need to manually reformat the string to look similar to:

2012-02-09T00:38:48.0000000

Or is there a way to have this actually converted?


Solution

  • You can use DateTime.TryParseExact to parse a string to a DateTime from any format you specify. There's a load of examples the bottom of this MSDN ref.