Kyaw Zin Wai Kyaw Zin Wai - 1 year ago 71
Objective-C Question

How can I set default calendar to gregorian in the Whole project? Objective c

I want to set the calendar to default Gregorian in whole project.
Even user change the calendar in Device Settings. But I want the calendar to only show the gregorian. In my case I don't want to use this code.

NSCalendar *gregcalendar = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
[formatter setCalendar:gregcalendar];

I want to set the calendar default to gregorian without using it. Is there anything else to do it? Like as set the calendar in Info.plist or something else. Please suggest me. Thank you very much.

Answer Source

Create a Singleton class Or Create global varibale in appDelegate class like this:

Add In Header File of your AppDelegate:

@property (nonatomic,strong) NSCalendar *gregorian;

Add In Implmenation file of your AppDelegate:

Use like this :

self.gregorian = [self calendar];

- (NSCalendar*)calendar
    if (self.gregorian == nil) {
        NSCalendar* temc = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

        NSLocale* usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"Add local code";

        self.gregorian = temc;
    return gregorian;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download