all groups > vj# > february 2005 >
You're in the

vj#

group:

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



J# java.util.Calendar bug???????? burtr
2/23/2005 9:02:49 AM
vj#: Hi,

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);
System.out.println(date.getTime());

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());

gives:

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.

Thanks,

Burt.
Re: J# java.util.Calendar bug???????? burtr
2/25/2005 5:13:10 PM
eh thanks! :)
Re: J# java.util.Calendar bug???????? Lars-Inge Tønnessen [VJ# MVP]
2/25/2005 8:37:45 PM

[quoted text, click to view]


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


Regards,
Lars-Inge Tønnessen

AddThis Social Bookmark Button