GregorianCalendar problem [message #256180] |
Mon, 08 September 2008 11:46  |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03509 seconds