문제

iOS provides a set of calendars, that can be used in an application. Here's the list of their ids:

NSString * const NSGregorianCalendar;
NSString * const NSBuddhistCalendar;
NSString * const NSChineseCalendar;
NSString * const NSHebrewCalendar;
NSString * const NSIslamicCalendar;
NSString * const NSIslamicCivilCalendar;
NSString * const NSJapaneseCalendar;
NSString * const NSRepublicOfChinaCalendar;
NSString * const NSPersianCalendar;
NSString * const NSIndianCalendar;
NSString * const NSISO8601Calendar;

What if I want to add more calendars. Let's say French Republican one (http://en.m.wikipedia.org/wiki/French_Republican_Calendar)?

I perfectly understand that I can use formula to convert dates, but is there a way to create own calendar to use just like the standard one, for example:

NSDateFormatter *formatter = [NSDateFormatter new];
formatter.calendar = [[NSCalendar alloc] initWithCalendarIdentifier:@"french_republican"]];
도움이 되었습니까?

해결책

As you have already mentioned showing NSLocale Calendar Keys there is a defined amount of calendars in iOS. You can not create your own using your custom identifier.

What you can do is to create some calendar decorator based on some standart calendar and will perform all the calculations using NSCalendar methods.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top