devxlogo

January 24, 2018

Using Calendar.getInstance()

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);Â