Convert Non DateTime String From One Format Into .NET DateTime

Lets say you are dealing with a mainframe system that handles Date/Time’s in this format:
2011-09-27-17.15.12.000000

You can convert this to a .NET DateTime by doing the following

dateString = "2011-09-27-17.15.12.000000";
DateTime result = DateTime.ParseExact(dateString, "yyyy-MM-dd-HH.mm.ss.ffffff", System.Globalization.DateTimeFormatInfo.CurrentInfo);
Advertisements