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

From: burtr (dhickey_at_gmail.com)
Date: 02/23/05


Date: 23 Feb 2005 09:02:49 -0800

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.



Relevant Pages

  • Re: simple compilaton question
    ... > before I try to compile Main? ... "javac *.java" in each of my java source file directories the first ... with gcj. ... slow to ask for help on mailing lists. ...
    (comp.lang.java.programmer)
  • Re: Java server wont run after reboot
    ... Working with classpaths in Java isn't too hard, ... package definitions in your source code. ... Execute from that directory, no classpath definition needed. ... Assuming that you compile your code in the same directory and deposit the ...
    (RedHat)
  • Re: Java programmer lured back by .Net (Questions)
    ... I have finally decided to put all my business logic in C++ and compile that to native code. ... Security is the only reason why I could see that being a problem but I'm sure there is a way around it. ... Of course it learned a lot from Java, and improved upon many things which Java is slowly catching up on. ... I would like to be able to place my executable on my remote server and then "load" the executables on demand from accross the internet - so that there are no executables on the local machine for prying eyes to reverse engineer. ...
    (microsoft.public.dotnet.distributed_apps)
  • Re: Standard Database Interface?
    ... Windows binary and examples athttp://aspn.activestate.com/ASPN/Cookbook/Tcl?kwd=TclBlend. ... use native tcl and binary packages. ... and Java i.e Tcl/TK 8.4.13 and Java 1.4.2.12. ... patient enough to show me a step by step method on how to compile ...
    (comp.lang.tcl)
  • Re: Java server wont run after reboot
    ... > package definitions in your source code. ... Execute from that directory, no classpath definition needed. ... > java HelloWorld ... > If you compile to a different location, ...
    (RedHat)