hi all,
have come across this code written by someone else and i dont understand the "gregoriancalendar.get()" part. How can a calender date be deduced from "get(1), get(2), get(5)" ??
I have looked up the API but i dont understand how get(5) can return date/time from default timezone/locale.
If you look at the GregorianCalendar API, you'll see that this class inherits a get(int) method from its Calendar parent. The int variable is a Calendar field, declared in static variables in the Calendar class. For example, static int MONTH, static int YEAR. These are static variables, with a value assigned to it. YEAR happens to be 1, MONTH 2, DAY_OF_MONTH 5 (check them here). By retrieving the yar, month and day, you can make a new calendar, the way it's done above. BUT.... never do it like this. Use Calendar.YEAR, Calendar.MONTH and other declared variables, not their values.
First of all, it's not a good idea to use numbers directly when calling the get() method - it makes it impossible to understand immediately what happens by just looking at the source code. Instead of using numbers, use the constants defined in class Calendar, for example:
Second, you should normally not use class GregorianCalendar directly.