• Post Reply Bookmark Topic Watch Topic
  • New Topic

final static variables In GregorianCalendar  RSS feed

 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.I was wondering why using the get method(c.get(c.HOUR_OF_DAY)); gives me the correct hour(currently 19) but directly accesing c.HOUR_OF_DAY returns 11 ?
It shows In the documentation that HOUR_OF_DAY is public.

 
Campbell Ritchie
Marshal
Posts: 56521
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know GregorianCalendar is notorious as a triumph of bad design?

You have lots of int fields, e.g. the one you have found, which happens to evaluate to 11.
When you pass that int to the get method, it doesn't mean return 11. It actually means something like, “I want the 11th value, please,” and that 11th value happens to be 19 in your instance. There are obviously lots of those values, including a 0th value, most probably. To find out all the field values, go to the GregorianCalendar API page and find the link called constant values.

Find out about the LocalDate class (Java8 only) which is much better.
 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the Info!
 
Campbell Ritchie
Marshal
Posts: 56521
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!