Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Visual J# / February 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
burtr - 23 Feb 2005 17:02 GMT
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.
Lars-Inge T?nnessen [VJ# MVP] - 25 Feb 2005 19:37 GMT
> So clearly this is a J# problem.

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

Regards,
Lars-Inge T?nnessen
burtr - 26 Feb 2005 01:13 GMT

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.