Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » GregorianCalendar problem
GregorianCalendar problem [message #256180] Mon, 08 September 2008 11:46 Go to next message
Eclipse UserFriend
hi all,
i am having a problem with my GregorianCalendar which is a month off
(ahead)

code excerpt is
GregorianCalendar c1 = new GregorianCalendar();
c1.set(2008,8,23);
Date caldate = c1.getTime();
System.out.println( "caldate =" + caldate);

output is

caldate =Tue Sep 23 11:41:10 EDT 2008

i expect to see Sat Aug 23, 2008

it is always a month ahead - ???
tyia
Re: GregorianCalendar problem [message #256184 is a reply to message #256180] Mon, 08 September 2008 11:57 Go to previous message
Eclipse UserFriend
fran wolanczyk a écrit :
> code excerpt is GregorianCalendar c1 = new GregorianCalendar();
> c1.set(2008,8,23);
> Date caldate = c1.getTime();
> System.out.println( "caldate =" + caldate);
>
> output is
> caldate =Tue Sep 23 11:41:10 EDT 2008
> it is always a month ahead - ???
> tyia
I think the javadoc of the set method is pretty clear. 0 = January. So
August is 7 not 8. To make your code clearly, you should use:
the constant java.util.Calendar.AUGUST instead of the constant 7.
See
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.h tml#set(int,%20int,%20int)
--
HTH,
Olivier
Previous Topic:ASTRewriter.createMoveTarget()
Next Topic:3.4 Hot Code Replace Failing
Goto Forum:
  


Current Time: Wed Sep 17 03:43:07 EDT 2025

Powered by FUDForum. Page generated in 0.05493 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top