DateTime.ParseExact( ) Exception

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.
 
N

Nathan Neitzke

Dave,
That is very odd - I just tried the code snippet on my machine and it worked
fine?

What version of the Framework are you using? Also, what OS?
 
J

Jon Skeet [C# MVP]

Dave P. said:
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?

Like Nathan, it works for me. What exception is thrown? Have you tried
searching for it on Google?
 
G

Guest

FCL version 1.1, OS Win2k server.

I don't have repro handy at the moment, but the exception
was FormatException, I think. Whatever it was, it was an
indication that the format string could not be used for
the date string.

I have done a Google search on this and haven't found
anything, which is why I'm posting here. But always a
good idea.

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top