J# java.util.Calendar bug????????

J# java.util.Calendar bug????????

Post by burt » Fri, 25 Feb 2005 02:02:49


I have a strange problem when adding a year to a 'leap' date. i.e.
2004/02/29 (yyyy/mm/dd) and wondering if anyone else has experienced
it. Basically J# code gives a different result than C# and Java. Check
out this code:

java.util.Calendar date = java.util.Calendar.getInstance();
date.set(2004, 1, 29, 0, 0, 0); //29th Feb 2004 - a leap day
date.add(java.util.Calendar.YEAR, 1);

When I compile this under Sun's JDK 1.4.2_06 and execute it (I use
Eclipse platform for Java development), the output I get is:

Mon Feb 28 00:00:00 GMT 2005

When I compile in a J# console application using VS.Net I get:

Tue Mar 01 00:00:00 GMT+00:00 2005

The dates are different! Does anyone know why this could be the case?

To compare, C# code:

DateTime date = new DateTime(2004, 2, 29);
date = date.AddYears(1);
Console.WriteLine("c#: " + date.ToString());


2/28/2005 12:00:00 AM

which is the same value as the Java compiled output. So clearly this is
a J# problem. Or is it?

Any help or info would be greatly appreciated.



J# java.util.Calendar bug????????

Post by Lars-Inge » Sun, 27 Feb 2005 04:37:45

Yes, I agree. It should give the same result as Java. Clearly a problem.

Lars-Inge Tnessen


J# java.util.Calendar bug????????

Post by burt » Sun, 27 Feb 2005 10:13:10

eh thanks! :)