This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why they have named a calendar method like this?

 
ramya narayanan
Ranch Hand
Posts: 338
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear noble ranchers,
We know we can get the date from the Calendar using the method



Actually it is leading to ambiguity as I think it should have been getDate() method.
What do you think?
Regards
 
Campbell Ritchie
Sheriff
Pie
Posts: 47281
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe there ought to have been a Calendar#getDate method, but a Calendar object does not record year, month, day. It records milliseconds since 1st Jan 1970 (negative numbers = before 1970) and calculates the date whenever the get method is called. [Have a look at the code: the values might be cached for future reference and only calculated once.] There are other possible ways to design a Calendar class, but that is the way the Java people at Sun chose to do it.
 
ramya narayanan
Ranch Hand
Posts: 338
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As usual thanks Campbell!
Regards
Note: Wondering how you are knowing even the trivia of details. That's why you've been a bartender.

 
Rob Spoor
Sheriff
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ramya narayanan wrote:

Just one note:
Calendar.getInstance() already returns a Calendar object for the current moment in time. The creation of the Date object and using it to set the time of the Calendar is not needed.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47281
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ramya narayanan wrote:Note: Wondering how you are knowing even the trivia of details.
Keep reading these fora Take notice when somebody tells me I am mistaken.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic