On 25 mar, 14:44, Rhino <no.offline.contact.ple...@example.com> wrote:
Can someone clarify for me the difference between:
GregorianCalendar now = new GregorianCalendar();
This one creates a new instance of GregorianCalendar.
and
Calendar now = Calendar.getInstance();
This one creates a Calendar instance. The concrete type of the created
Calendar instance depends on the default timezone and locale. If you
look at the source code, you'll discover that it usually creates a
GregorianCalendar instance, but can also create a BuddhistCalendar or
JapaneseImperialCalendar instance.
and
Calendar now = GregorianCalendar.getInstance();
This one actually calls Calendar.getInstance(), since there is no
getInstance method in GregorianCalendar. It's thus exactly the same as
the previous one, except I would consider it bad style.
I'm really not clear on what each does and when I would prefer one
over t
he
other.
If you want a Calendar instance that is the most appropriate for the
country and locale of the system where your app is executing, use
Calendar.getInstance(). If you *need* a GregorianCalendar, regardless
of the default locale and timezone, use new GregorianCalendar().
JB.
(I assume each one is preferred in some situation or another.)
--
Rhino