We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Using Calendar.getInstance()

Submitted by: Octavia Anghel(octaviaanghel@gmail.com)

Wednesday Jan 24th 2018 by Octavia Anghel

Language: Java, Level: Beginner: - Learn why you should avoid using the Calendar.getInstance() in many instances.

Calendar c = Calendar.getInstance();
c.set(2017, Calendar.OCTOBER, 29); 

This code behave as a Gregorian calendar, but if the returned Calendar subclass is a Islamic, Julian, Buddistic or Hebrew calendar, then the month called October or the year 2017, doesn't exist. Calendar.getInstance() uses the current default locale to select an appropiate implementation. The utility of Calendar.getInstance() is very limited  and it should be avoided because it's results is not properly defined.

Calendar c = new GregorianCalendar (timeZone);
c.set(2017, Calendar.OCTOBER, 29); 

Mobile Site | Full Site
Copyright 2018 © QuinStreet Inc. All Rights Reserved