Skip to content

Instantly share code, notes, and snippets.

@eienf
Created October 7, 2012 08:57
Show Gist options
  • Save eienf/3847580 to your computer and use it in GitHub Desktop.
Save eienf/3847580 to your computer and use it in GitHub Desktop.
Print all era in Japanese Calendar (Japanese/English).
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSCalendar *japanese = [[NSCalendar alloc] initWithCalendarIdentifier:NSJapaneseCalendar];
NSDateFormatter *usFormatter = [[NSDateFormatter alloc] init];
usFormatter.calendar = japanese;
usFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
usFormatter.dateFormat = @"G";
NSDateFormatter *aFormatter = [[NSDateFormatter alloc] init];
aFormatter.calendar = japanese;
aFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"ja_JP"];
aFormatter.dateFormat = @"G";
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];
printf("%s %s\n",
[[aFormatter stringFromDate:aDate] UTF8String],
[[usFormatter stringFromDate:aDate] UTF8String]);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment