GregorianCalendar or just a calendar

Although I read a lot about the calendar and gregoriancalendar, there are still some difficulties. Which is better or what can you recommend? I can not understand the difference.

GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance(); 

or

 Calendar c = Calendar.getInstance(); 

what do you say

+4
source share
3 answers

Calendar is an abstract class, the getInstance method returns one of the implementations depending on the locale of your system by default. This means that if you use European or American, you will still use the Gregorian calendar.

In any case, you should always try to use the implementation in accordance with the area in which you are located, if the application is in Japan, you may have some problems because the Japanese calendar is slightly different, for example

You can check it in the Android documentation: here

+6
source

If you do not need to work with other types of calendars, use GregorianCalendar. But, if you want more frexibility, use Calendar.

You can read this mail-archive where this question is discussed.

Just one note: To have fewer casting issues, it's best to declare a Calendar object and initialize it as a GregorianCalendar. Here is an example: Calendar gregorian = new GregorianCalendar();

+2
source

If you need to manipulate some dates, it is easier to use GragorianCalendar!

-1
source

All Articles