Hi, whilst reading a book on Java, I came across a bit where the author used

GregorianCalendar now = new GregorainCalendar();

And I was just wondering, is that any different from

Calendar now = Calendar.getInstance();

And if so, why did he use GregorianCalendar instead of the normal one?

try this web link and read the comments at top:

http://java.sun.com/j2se/1.4.2/docs/api/java/util/GregorianCalendar.html

essentially as it says:

This implementation handles a single discontinuity, which corresponds by default to the date the Gregorian calendar was instituted (October 15, 1582 in some countries, later in others). The cutover date may be changed by the caller by calling setGregorianChange().

// end quote

I think this would be useful if you have an application that uses historical time. One method is i'm going to feed you dates based on how we understand the calander works now with that date of change over, the gregorian seems to say if we are in a period of history were they may or may not have used gregorian time i can handle it. The calander before gregorian ( what we use now ) was julian which can be off a few days as you go back centuries do to slightly different leap year rules. i think they ommit skipping a leap year every 400 years in julian.

Mike

GregorianCalendar(concrete class) is a subclass of Calendar(abstract class).So u can use either....So u can say GregorianCaendar c=new GregorianCalendar.......thanks

Thanks for the help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.