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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s