Last active
December 18, 2015 22:39
-
-
Save naokits/5856139 to your computer and use it in GitHub Desktop.
簡単に昭和と西暦、平成と西暦を変換
This file contains 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
/** | |
* 昭和64年 = 平成元年 = 1989年というルールから、簡単に昭和と西暦、平成と西暦を変換 | |
*/ | |
#import <Foundation/Foundation.h> | |
#define HEISEI_MAGIC_NUMBER 12 | |
#define SHOWA_MAGIC_NUMBER 25 | |
@interface Hoge : NSObject | |
- (void)heiseiFromSeireki:(NSInteger)seireki; | |
- (void)seirekiFromHeisei:(NSInteger)heisei; | |
- (void)showaFromSeireki:(NSInteger)seireki; | |
- (void)seirekiFromShowa:(NSInteger)showa; | |
@end | |
@implementation Hoge | |
/** | |
* 西暦 --> 平成 | |
*/ | |
- (void)heiseiFromSeireki:(NSInteger)seireki | |
{ | |
NSInteger hoge = (seireki + HEISEI_MAGIC_NUMBER) - 2000; | |
NSLog(@"平成%d年", hoge); | |
} | |
/** | |
* 平成 --> 西暦 | |
*/ | |
- (void)seirekiFromHeisei:(NSInteger)heisei | |
{ | |
NSInteger seireki = (heisei - HEISEI_MAGIC_NUMBER) + 2000; | |
NSLog(@"西暦%d年", seireki); | |
} | |
/** | |
* 西暦 --> 昭和 | |
*/ | |
- (void)showaFromSeireki:(NSInteger)seireki | |
{ | |
NSInteger hoge = (seireki - SHOWA_MAGIC_NUMBER) - 1900; | |
NSLog(@"昭和%d年", hoge); | |
} | |
/** | |
* 昭和 --> 西暦 | |
*/ | |
- (void)seirekiFromShowa:(NSInteger)showa | |
{ | |
NSInteger seireki = (showa + SHOWA_MAGIC_NUMBER) + 1900; | |
NSLog(@"西暦%d年", seireki); | |
} | |
@end | |
int main(int argc, char *argv[]) { | |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
Hoge *h = [[Hoge alloc] init]; | |
[h heiseiFromSeireki:2013]; | |
[h seirekiFromHeisei:25]; | |
[h showaFromSeireki:1966]; | |
[h seirekiFromShowa:41]; | |
[pool release]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment