• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

date question

 
George Liao
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
System.out.println(
"=======cal.get(Calendar.YEAR) =" + cal.get(Calendar.YEAR));
System.out.println(
"=======cal.get(Calendar.MONTH) =" + cal.get(Calendar.MONTH));
System.out.println(
"=======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
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
George Liao
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joel, thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic