[Mono-dev] DateTime.Parse difference with .NET

Atsushi Eno atsushi at ximian.com
Tue Aug 9 00:30:19 EDT 2005


Martin Hinks wrote:
> using System;
> namespace DateFail
> {
> 	class MainClass
> 	{
> 		public static void Main(string[] args)
> 		{
> 			DateTime.Parse("17/07/2005 00:00:00");
> 		}
> 	}
> }
> .NET Framework 1.1 result: Success
> Mono 1.1.8 result: 
> Unhandled Exception: System.FormatException: String was not recognized as 
> a vali
> d DateTime.
> in <0x000e5> System.DateTime:Parse (System.String s, IFormatProvider fp, 
> DateTim
> eStyles styles)
> in <0x00016> System.DateTime:Parse (System.String s, IFormatProvider fp)
> in <0x00013> System.DateTime:Parse (System.String s)
> in <0x00013> DateFail.MainClass:Main (System.String[] args)
> I submitted it to BugZilla - just wanted to make sure I'm not doing
> anything stupid and also wondered if someone had a workaround?

In fact using DateTime.Parse() is somewhat stupid ;-) Read here:


	The DateTime.Parse method in the Microsoft .NET Framework
	has goals much like its predecessors, but unfortunately it
	suffers from some of the same problems. The code is slower
	since the extra checking takes time, and there will always
	be some new format that is not properly detected. In those
	older products, you may remember, the behavior was sometimes
	disparagingly referred to as "evil date parsing."

At least DateTime.Parse() is COM dependent where the behavior is
totally unpredictable and not countable from DateTimeFormatInfo.

Atsushi Eno

More information about the Mono-devel-list mailing list