Getting current datetime using Calendar.getInstance() vs new GregorianCalendar()

Oh Chin Boon picture Oh Chin Boon · Aug 2, 2011 · Viewed 26.6k times · Source

What might be the difference between getting datetime using

Calendar.getInstance()

vs

new GregorianCalendar()

?

Answer

user802421 picture user802421 · Aug 2, 2011

Looking in the source of Calendar.getInstance():

private static Calendar createCalendar(TimeZone zone, Locale aLocale) {
    // If the specified locale is a Thai locale, returns a BuddhistCalendar
    // instance.
    if ("th".equals(aLocale.getLanguage())
        && ("TH".equals(aLocale.getCountry()))) {
        return new sun.util.BuddhistCalendar(zone, aLocale);
    } else if ("JP".equals(aLocale.getVariant())
        && "JP".equals(aLocale.getCountry())
        && "ja".equals(aLocale.getLanguage())) {
        return new JapaneseImperialCalendar(zone, aLocale);
    }       

    // else create the default calendar
    return new GregorianCalendar(zone, aLocale);    
}

So getInstance() will return a Calendar based on your default Locale and TimeZone.