PC Review


Reply
Thread Tools Rate Thread

DateTime.Parse .. what's different in .NET 1.1

 
 
Atul Agarwal
Guest
Posts: n/a
 
      23rd Aug 2003
Hello

In .NET 1.0, the following code worked fine


public string dateFormat = "yyy-MM-dd\"T\"HH:mm:ss.fff zzz";
DateTime date, minDate;

date = DateTime.Parse(minDate.ToString(dateFormat));

In .NET 1.1 I get an System.Format exception
For Example, this generates a System.Format exception

DateTime.Parse("2003-08-23T20:50:05.365 +05:30");

Is something changed in .NET 1.1 ?

Thanks

Atul Agarwal
(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Jerry III
Guest
Posts: n/a
 
      23rd Aug 2003
yyy is not a valid format string. It's either y, yy or yyyy.

Jerry

"Atul Agarwal" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello
>
> In .NET 1.0, the following code worked fine
>
>
> public string dateFormat = "yyy-MM-dd\"T\"HH:mm:ss.fff zzz";
> DateTime date, minDate;
>
> date = DateTime.Parse(minDate.ToString(dateFormat));
>
> In .NET 1.1 I get an System.Format exception
> For Example, this generates a System.Format exception
>
> DateTime.Parse("2003-08-23T20:50:05.365 +05:30");
>
> Is something changed in .NET 1.1 ?
>
> Thanks
>
> Atul Agarwal
> (E-Mail Removed)



 
Reply With Quote
 
Atul Agarwal
Guest
Posts: n/a
 
      24th Aug 2003
Ah .. apologies my mistake. But in any case that was not the source
of the problem.

In .NET 1.1, this throws a SystemFormat exception
DateTime.Parse("2003-08-23T20:50:05.365 +05:30");
but it worked fine in .NET 1.0.

It is the extra space before the timezone which is the cause of
the problem. It is not standard ISO8601 format.
Thus the following format string should have been used

"yyyy-MM-dd\"T\"HH:mm:ss.fffzzz";

Atul Agarwal





"Jerry III" <(E-Mail Removed)> wrote in message news:<OQ#(E-Mail Removed)>...
> yyy is not a valid format string. It's either y, yy or yyyy.
>
> Jerry
>
> "Atul Agarwal" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hello
> >
> > In .NET 1.0, the following code worked fine
> >
> >
> > public string dateFormat = "yyy-MM-dd\"T\"HH:mm:ss.fff zzz";
> > DateTime date, minDate;
> >
> > date = DateTime.Parse(minDate.ToString(dateFormat));
> >
> > In .NET 1.1 I get an System.Format exception
> > For Example, this generates a System.Format exception
> >
> > DateTime.Parse("2003-08-23T20:50:05.365 +05:30");
> >
> > Is something changed in .NET 1.1 ?
> >
> > Thanks
> >
> > Atul Agarwal
> > (E-Mail Removed)

 
Reply With Quote
 
Jon Skeet
Guest
Posts: n/a
 
      25th Aug 2003
Yan-Hong Huang[MSFT] <(E-Mail Removed)> wrote:
> If there is no T inside the string, the string could be parsed correctly.
> Could you please let us know why there is a T in the string?


Presumably because it was meant to be ISO8601 compliant, which means
including a T. From the MSDN sample of output patterns, using standard
formatter s which (according to the docs) conforms to 8601:

2001-04-10T15:51:24

Also from the MSDN:

<quote>
The property references the CultureInfo.InvariantCulture property, and
the format follows the custom pattern "yyyy-MM-ddTHH:mm:ss".
</quote>

The T should definitely be there as far as I can see.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
 
Reply With Quote
 
Yan-Hong Huang[MSFT]
Guest
Posts: n/a
 
      27th Aug 2003
Hello Atul and Jon,

After working with product group, we have confirmed that it is a product
issue here. It has been fixed in the next version of VS.NET.

Here are some work around options:

1. Configure the source of the data to not format the dates with a space.
2. Use PaseExact('yyyy-MM-dd'T'HH:mm:ss.fff zzz') instead.
3. Clean up the data using String.Replace or a Regex replace.

Please post here to let us know if you have follow up questions. Thanks
very much for your feedback on the product. We appreciate it very much.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!From: Jon Skeet <(E-Mail Removed)>
!Subject: Re: DateTime.Parse .. what's different in .NET 1.1
!Date: Mon, 25 Aug 2003 19:25:34 +0100
!Message-ID: <(E-Mail Removed)>
!References: <(E-Mail Removed)>
<OQ#(E-Mail Removed)>
<(E-Mail Removed)>
<(E-Mail Removed)>
!Organization: Peramon Technology Ltd.
!X-Newsreader: MicroPlanet Gravity v2.60
!Newsgroups: microsoft.public.dotnet.framework
!NNTP-Posting-Host: pc3-rdng5-6-cust64.winn.cable.ntl.com 81.103.154.64
!Lines: 1
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:52161
!X-Tomcat-NG: microsoft.public.dotnet.framework
!
!Yan-Hong Huang[MSFT] <(E-Mail Removed)> wrote:
!> If there is no T inside the string, the string could be parsed
correctly.
!> Could you please let us know why there is a T in the string?
!
!Presumably because it was meant to be ISO8601 compliant, which means
!including a T. From the MSDN sample of output patterns, using standard
!formatter s which (according to the docs) conforms to 8601:
!
!2001-04-10T15:51:24
!
!Also from the MSDN:
!
!<quote>
!The property references the CultureInfo.InvariantCulture property, and
!the format follows the custom pattern "yyyy-MM-ddTHH:mm:ss".
!</quote>
!
!The T should definitely be there as far as I can see.
!
!--
!Jon Skeet - <(E-Mail Removed)>
!http://www.pobox.com/~skeet/
!If replying to the group, please do not mail me too
!

 
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.Parse() vs DateTime.ParseExact() Peter Duniho Microsoft C# .NET 3 19th Jun 2007 03:19 PM
DateTime.Parse() js Microsoft ASP .NET 5 4th Oct 2006 11:38 PM
Weird CultureInfo - DateTime.Parse() and Decimal.Parse() Rico Microsoft C# .NET 8 22nd Sep 2006 10:59 AM
DateTime parse ahager via DotNetMonster.com Microsoft ADO .NET 2 4th Oct 2005 03:14 AM
Parse datetime =?Utf-8?B?ZHdpZ2h0?= Microsoft C# .NET 4 18th May 2005 02:24 PM


Features
 

Advertising
 

Newsgroups
 


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