Last active
August 29, 2015 13:56
-
-
Save FrankWu100/9046985 to your computer and use it in GitHub Desktop.
PCCU YYM Objective-C
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
// | |
// PCCUYYM.h | |
// ClassComment | |
// | |
// Created by FrankWu on 2014/2/17. | |
// Copyright (c) 2014年 FrankWu. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface PCCUYYM : NSObject | |
{ | |
NSString *YYM; | |
} | |
- (NSString *)getYYM; | |
- (NSString *)getYY; | |
- (NSString *)getM; | |
@end |
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
// | |
// PCCUYYM.m | |
// ClassComment | |
// | |
// Created by FrankWu on 2014/2/17. | |
// Copyright (c) 2014年 FrankWu. All rights reserved. | |
// | |
#import "PCCUYYM.h" | |
@implementation PCCUYYM | |
- (void)setYYM | |
{ | |
NSDateFormatter *formatter_yyyy = [[NSDateFormatter alloc] init]; | |
[formatter_yyyy setDateFormat:@"yyyy"]; | |
NSDateFormatter *formatter_mm = [[NSDateFormatter alloc] init]; | |
[formatter_mm setDateFormat:@"MM"]; | |
NSDate *dateNow = [NSDate date]; | |
NSString *yyyyStr = [NSString stringWithString:[formatter_yyyy stringFromDate:dateNow]]; | |
NSString *mmStr = [NSString stringWithString:[formatter_mm stringFromDate:dateNow]]; | |
// NSLog(@"STR - YY: %@ M: %@", yyyyStr, mmStr); | |
int yyyyNum = [yyyyStr intValue]; | |
int mmNum = [mmStr intValue]; | |
// NSLog(@"INT - YY: %d M: %d", yyyyNum, mmNum); | |
if (mmNum < 2) { | |
//上學期 | |
// NSLog(@"PCCU- YY: %03d M: %d", yyyyNum - 1911 - 1, 1); | |
YYM = [NSString stringWithFormat:@"%03d%d", yyyyNum - 1911 - 1, 1]; | |
} | |
else if (mmNum >= 8) { | |
//上學期 | |
// NSLog(@"PCCU- YY: %03d M: %d", yyyyNum - 1911, 1); | |
YYM = [NSString stringWithFormat:@"%03d%d", yyyyNum - 1911, 1]; | |
} | |
else if (mmNum >= 2 && mmNum < 8) { | |
//下學期 | |
// NSLog(@"PCCU- YY: %03d M: %d", yyyyNum - 1911 - 1, 2); | |
YYM = [NSString stringWithFormat:@"%03d%d", yyyyNum - 1911 - 1, 2]; | |
} | |
} | |
- (NSString *)getYYM | |
{ | |
if ([YYM length] == 0) { | |
[self setYYM]; | |
} | |
return YYM; | |
} | |
- (NSString *)getYY | |
{ | |
return [[self getYYM] substringWithRange:NSMakeRange(0, 3)]; | |
} | |
- (NSString *)getM | |
{ | |
return [[self getYYM] substringWithRange:NSMakeRange(3, 1)]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment