Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / December 2003

Tip: Looking for answers? Try searching our database.

Problem with DateTime.ParseExact

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Fred Strauss - 12 Dec 2003 13:30 GMT
I am having an odd problem using the DateTime.ParseExact() method that
I'm hoping someone can help me with.

I have XML files that use 2 different date formats internally. I am
trying to use the same call to ParseExact to parse either format. I am
using C# to call the following form of ParseExact:

public static DateTime ParseExact(string, string[], IFormatProvider,
DateTimeStyles);

Examples of the 2 formats I'm passing in the source string are:

20031211T151302Z

and

2003-12-03T16:32:00-5:00

The format strings I'm passing in the 2nd argument are defined with:

private string[] sDateFormats = new string[] {"yyyyMMdd\\THHmmss\\Z",
"yyyy\\-MM\\-dd\\THH:mm:sszzz"};

The problem is that when I attempt to parse dates in the 2nd format a
FormatException is thrown.

Any help is greatly appreciated

Fred Strauss
Project Manager
Associated Press
212-621-1968
fred_strauss@ap.org
Anthony Moore - 22 Dec 2003 23:42 GMT
Hello Fred. I'm the development owner of the DateTime class.

I could not come up with an exlplanation for what you were seeing, so I got
your repro and debugged it. I think you have found a valid bug in the
product and I have fixed it for the next release (Whidbey).

The problem is that ParseExact cannot parse a value like "-5:00" for the
"zzz" format. It requires two leading digits like so: "-05:00". This is a
bug, because DateTime.Parse will accept a single leading digit, and the
ISO8601 allows it also.

Hopefully passing in "-05:00" can be an effective work-around to unblock
you here. In general, Parse and Exact are good at round-tripping a value
the exact same way that it is formatted by ToString. If you are having
trouble with a format, try calling ToString on the format to determine what
it is looking for.

Thanks very much for asking the question. It allows us to make the product
better, and will help you determine if it is pilot error. I hope this does
not inconvience you too much.

Anthony.

--------------------
| From: Fred Strauss <frauss@comcast.net>
| Subject: Problem with DateTime.ParseExact
[quoted text clipped - 5 lines]
| Content-Transfer-Encoding: 7bit
| Newsgroups:
microsoft.public.dotnet.framework.clr,microsoft.public.dotnet.languages.csha
rp
| NNTP-Posting-Host: pcp01721375pcs.union01.nj.comcast.net 68.37.29.230
| Lines: 1        
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTNGXS01.phx.gbl!TK2MSFTNGXA0
5.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa07.phx.gbl
microsoft.public.dotnet.languages.csharp:205152
microsoft.public.dotnet.framework.clr:8979
| X-Tomcat-NG: microsoft.public.dotnet.framework.clr
|
[quoted text clipped - 31 lines]
| 212-621-1968
| fred_strauss@ap.org
Fred Strauss - 23 Dec 2003 11:52 GMT
Anthony, thanks for getting back to me.

I've already got a workaround but it's nice to know I wasn't losing my
mind in thinking this should have worked.

Fred

>Hello Fred. I'm the development owner of the DateTime class.
>
[quoted text clipped - 74 lines]
>| 212-621-1968
>| fred_strauss@ap.org

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.