PC Review


Reply
Thread Tools Rate Thread

DateTime.ParseExact( ) Exception

 
 
Dave P.
Guest
Posts: n/a
 
      15th Mar 2005
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.

 
Reply With Quote
 
 
 
 
Nathan Neitzke
Guest
Posts: n/a
 
      15th Mar 2005
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?

--
Nathan

"Dave P." <(E-Mail Removed)> wrote in message
news:700501c52906$3bbdbc40$(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      15th Mar 2005
Dave P. <(E-Mail Removed)> wrote:
> 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?

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Guest
Posts: n/a
 
      15th Mar 2005
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
>-----Original Message-----
>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?
>
>--
>Nathan
>
>"Dave P." <(E-Mail Removed)> wrote in

message
>news:700501c52906$3bbdbc40$(E-Mail Removed)...
>> 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.
>>

>
>
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DateTime.ParseExact mit Wildcards Torsten Kraus Microsoft Dot NET Framework 3 10th Jul 2007 12:17 PM
DateTime.Parse() vs DateTime.ParseExact() Peter Duniho Microsoft C# .NET 3 19th Jun 2007 03:19 PM
DateTime and ParseExact =?Utf-8?B?c2lwcHl1Y29ubg==?= Microsoft C# .NET 2 12th Apr 2007 03:58 AM
DateTime.ParseExact(..) Pablo Microsoft VB .NET 1 16th Aug 2006 01:25 PM
DateTime.ParseExact( ) usage Dave P Microsoft Dot NET Framework 1 23rd Mar 2005 12:13 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:57 AM.