开发者

GregorianCalendar or just Calendar

Although i read a lot about the calendar and gregoriancalendar, still some complications arise. Which is better or what can you recommend to use? I cant not figure out the difference.

开发者_如何学JAVA
GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance();

or

Calendar c = Calendar.getInstance();

what do you say?


Calendar is an abstract class, the getInstance method returns one of is implementations depending on the default Locale of your system. This means that if you are using an European or American locale, you'll be using the Gregorian Calendar anyway.

In any case, you should always try to use the Implementation according to the area you are, if the application is in Japan, you may have some problems, because the Japanese calendar is a bit different, for example

You can check it in the Android documentation: here


If you don't need work with other kind of calendars, use GregorianCalendar. But, if you want more frexibility, then use Calendar.

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

Only one remark: In order to have less cast problems, it's better declare a Calendar object and initialize as GregorianCalendar. Here's an example: Calendar gregorian = new GregorianCalendar();


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜