Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What does Calendar.getInstance() Retreive?

 
Vishal Hegde
Ranch Hand
Posts: 1077
Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

i tried to printout Calendar.getInstance() and I am getting the below output. Why I am getting such big output I thought it will get me the current Calendar date.


 
Paul Clapham
Sheriff
Pie
Posts: 20750
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, yes, you are getting the current date and time. And also the default time zone. You can see all of that in your output, which is simply the result of calling the toString() method of the Calendar object. Which by the way is an instance of java.util.GregorianCalendar; toString() tells you that as well.

Of course if you want to work with the Calendar and do things like find out whether it's Saturday or the last day of the month or whether it's more than 30 days after the invoice you have elsewhere in your code, then you can call other methods of the Calendar to do that. You wouldn't use toString() for that purpose.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic