Skip to content

Instantly share code, notes, and snippets.

@eienf
Created October 5, 2012 09:29
Show Gist options
  • Save eienf/3838919 to your computer and use it in GitHub Desktop.
Save eienf/3838919 to your computer and use it in GitHub Desktop.
Print all era in Japanese Calendar.
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSCalendar *japanese = [[NSCalendar alloc] initWithCalendarIdentifier:NSJapaneseCalendar];
NSLocale *aLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
NSDateComponents *comps = [[NSDateComponents alloc] init];
comps.year = 1;
comps.month = 12;
comps.day = 31;
for (comps.era = 235; comps.era >= 0; comps.era--) {
NSDate *aDate = [japanese dateFromComponents:comps];
NSDateFormatter *aFormatter = [[NSDateFormatter alloc] init];
aFormatter.calendar = japanese;
aFormatter.locale = aLocale;
aFormatter.dateFormat = @"G y/M/d";
NSLog(@"%@",[aFormatter stringFromDate:aDate]);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment