Here is stuff:
http://www.javalaunch.com/Java-Date-Calender-time-2.html
Anyone can tell me what is the logic behind this Calendar.YEAR and calender.get(Calendar.YEAR).Actually i dont understand this .
System.out.println("Year: " + Calendar.YEAR);
System.out.println("month: " + Calendar.MONTH);
System.out.println("dayOfMonth: " + Calendar.DAY_OF_MONTH); // Jan = 0, not 1
System.out.println("dayOfWeek: " + Calendar.DAY_OF_WEEK);
System.out.println("weekOfYear: " + Calendar.WEEK_OF_YEAR);
System.out.println("weekOfMonth: " + Calendar.WEEK_OF_MONTH);
System.out.println("hour: " + Calendar.HOUR); // 12 hour clock
System.out.println("hourOfDay: " + Calendar.HOUR_OF_DAY); // 24 hour clock
System.out.println("minute: " + Calendar.MINUTE);
System.out.println("second: " + Calendar.SECOND);
System.out.println("millisecond: " + Calendar.MILLISECOND);
System.out.println("...................................................................................");
Calendar calender = new GregorianCalendar();
System.out.println("Year: " + calender.get(Calendar.YEAR));
System.out.println("month: " + calender.get(Calendar.MONTH));
System.out.println("dayOfMonth: " + calender.get(Calendar.DAY_OF_MONTH)); // Jan = 0, not 1
System.out.println("dayOfWeek: " + calender.get(Calendar.DAY_OF_WEEK));
System.out.println("weekOfYear: " + calender.get(Calendar.WEEK_OF_YEAR));
System.out.println("weekOfMonth: " + calender.get(Calendar.WEEK_OF_MONTH));
System.out.println("hour: " + calender.get(Calendar.HOUR)); // 12 hour clock
System.out.println("hourOfDay: " + calender.get(Calendar.HOUR_OF_DAY)); // 24 hour clock
System.out.println("minute: " + calender.get(Calendar.MINUTE));
System.out.println("second: " + calender.get(Calendar.SECOND));
System.out.println("millisecond: " + calender.get(Calendar.MILLISECOND));
OutPut:
Year: 1
month: 2
dayOfMonth: 5
dayOfWeek: 7
weekOfYear: 3
weekOfMonth: 4
hour: 10
hourOfDay: 11
minute: 12
second: 13
millisecond: 14
...................................................................................
Year: 2014
month: 11
dayOfMonth: 24
dayOfWeek: 4
weekOfYear: 52
weekOfMonth: 4
hour: 11
hourOfDay: 11
minute: 51
second: 54
millisecond: 687
When your using (Calendar.YEAR, Calendar.MONTH),
these are the static fields in the Calendar class
and if you are printing those it will print default values for those fields.
In case of
Calendar calendar = new GregorianCalendar();
this will create a new instance of calendar with the current time and date values and you are using those static final variables to get that particular value from the newly created calendar instance.
you can check documentation for Calender here
UPDATE
Below is the code for get method, when you pass those static fields to get the method, it will return value for that field from fields array for that index.
public int get(int field)
{
complete();
return internalGet(field);
}
protected final int internalGet(int field)
{
return fields[field];
}