Created
October 7, 2012 08:57
-
-
Save eienf/3847580 to your computer and use it in GitHub Desktop.
Print all era in Japanese Calendar (Japanese/English).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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