On Mon, 29 Sep 2003 12:57:45 -0700, John Bowling wrote:
I'm trying to get the day of month with:
int dayofmonth;
dayofmonth = Calendar.get(Calendar.DAY_OF_MONTH);
and I get the compile time error of saying get(int) is a not-static method.
Is there a process (or a different class/method to call) that will work?
Thanks, John
Hi John,
When get is not defined as static this means that you have to create a
GregorianCalendar object and call get on that; I guess this is because the
creators of the class wanted programmers to be able to give the calendar
their own layout.
Here is an example on how to set up a GregorianCalendar object (most is from Java's API):
String[] ids = TimeZone.getAvailableIDs(1 * 60 * 60 * 1000);
if (ids.length == 0)
System.exit(0);
SimpleTimeZone pdt = new SimpleTimeZone(1 * 60 * 60 * 1000, ids[0]);
pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
GregorianCalendar calendar = new GregorianCalendar(pdt);
calendar.setTime(new java.util.Date());
int dayofmonth = calendar.get(Calendar.DAY_OF_MONTH);
Best Regard
Kristian