GregorianCalendar 或只是日历
尽管我读了很多有关日历和公历的内容,但仍然出现了一些复杂情况。哪个更好或者您可以推荐使用什么?我无法弄清楚其中的区别。
GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance();
或者
Calendar c = Calendar.getInstance();
你说什么?
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.
GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance();
or
Calendar c = Calendar.getInstance();
what do you say?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您不需要使用其他类型的日历,请使用 GregorianCalendar。但是,如果您想要更多灵活性,请使用日历。
您可以阅读此 邮件-该主题的存档正在讨论。
只有一处备注:
为了减少转换问题,最好声明一个 Calendar 对象并初始化为 GregorianCalendar。下面是一个示例:
Calendar gregorian = new GregorianCalendar();
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();
如果您需要操作一些日期,使用 GragorianCalendar 更容易!
If you need to manipulate some dates, it's easier to use GragorianCalendar!
Calendar 是一个抽象类, getInstance 方法根据系统的默认区域设置返回其中一种实现。这意味着,如果您使用欧洲或美国语言环境,则无论如何您都将使用公历。
无论如何,你应该始终根据你所在的地区尝试使用实现,如果应用程序在日本,你可能会遇到一些问题,因为日本的日历有点不同,例如
你可以在Android中检查它文档:此处
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