Question

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"]];
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top