DateTime.ParseExact( ) usage

  • Thread starter Thread starter Dave P
  • Start date Start date
D

Dave P

I'm trying to parse a string into a DateTime object. I
want to try using ParseExact to see if I can improve
performance of a frequently-called method (i.e., please
don't suggest using Parse()). My code looks like this:

IFormatProvider fp = new System.Globalization.CultureInfo
("en-US");
DateTime dt = DateTime.ParseExact("Mar 9, 2005", "MMM d,
yyyy", fp);

This throws an exception in MatchAbbreviatedMonthName()
(an FCL method). If I look at the CultureInfo object,
there is, in fact, a month called "Mar".

How can I use my custom format with ParseExact?

Thanks!

Dave P.
 
From: "Dave P said:
IFormatProvider fp = new System.Globalization.CultureInfo
("en-US");
DateTime dt = DateTime.ParseExact("Mar 9, 2005", "MMM d,
yyyy", fp);

This throws an exception in MatchAbbreviatedMonthName()
(an FCL method). If I look at the CultureInfo object,
there is, in fact, a month called "Mar".

I'm seeing no error and a successful parse with ParseExact, using either
v1.0, v1.1, or v2.0. Are you modifying the CultureInfo object before using
it? Is the month string "Mar" without a period? What version of the
framework are you using?

Katy
 
Back
Top