This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes date question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "date question" Watch "date question" New topic

date question

George Liao

Joined: May 20, 2003
Posts: 14
I run the following code:
Calendar cal = Calendar.getInstance();
System.out.println("=======Calendar.YEAR = " + Calendar.YEAR);
System.out.println("=======Calendar.MONTH =" + Calendar.MONTH);
System.out.println("=======Calendar.DATE = "+ Calendar.DATE);
"=======cal.get(Calendar.YEAR) =" + cal.get(Calendar.YEAR));
"=======cal.get(Calendar.MONTH) =" + cal.get(Calendar.MONTH));
"=======cal.get(Calendar.DATE) =" + cal.get(Calendar.DATE));

The results are:
=======Calendar.YEAR = 1
=======Calendar.MONTH =2
=======Calendar.DATE = 5
=======cal.get(Calendar.YEAR) =2003
=======cal.get(Calendar.MONTH) =11
=======cal.get(Calendar.DATE) =23
What does it mean by Calendar.YEAR? Why the value is 1?
Joel McNary

Joined: Aug 20, 2001
Posts: 1815
Calendar.YEAR is an integer value that represents the field in the calender that you want to retrieve. That is, if the Calendar object were implemented as an array (which it isn't), you could get the year by returning the value at calendar[1].
Generally, you shouldn't need to worry about the exact values of the Calendar constants; that should be transparent to any code that you write.

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
George Liao

Joined: May 20, 2003
Posts: 14
Joel, thanks.
I agree. Here's the link:
subject: date question
Similar Threads
java calander class
java calander class
Tommorows date
How to get end week date from given start date??
Date Problem