aspose file tools
The moose likes Java in General and the fly likes What does Calendar.getInstance() Retreive? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "What does Calendar.getInstance() Retreive?" Watch "What does Calendar.getInstance() Retreive?" New topic

What does Calendar.getInstance() Retreive?

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1056

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. || OCJP:81%
Paul Clapham

Joined: Oct 14, 2005
Posts: 19119

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.
I agree. Here's the link:
subject: What does Calendar.getInstance() Retreive?