Friday, August 27, 2010

DateTime.ParseExact

So after never having had CultureInfo.CurrentCulture on my radar, I ended up using it twice this week.

For the first use, see my previous post on ToUpperInvariant().

Today, I ran into a problem where I tried DateTime.Parse on a string which I had generated in a gridview using:

<asp:BoundField DataField="DateStarted"
  DataFormatString="{0:ddd MMM d hh:mmtt}" />
The compiler couldn't parse it.

I ended up having to decode it using the following:

DateTime dateCreated =DateTime.ParseExact(sdateCreated,
  "ddd MMM d hh:mmtt", CultureInfo.InvariantCulture);

No comments:

Post a Comment