- (NSString *)getChineseCalendarWithDate:(NSInteger)day month:(NSInteger)month year:(NSInteger)year{
NSArray *chineseDays=[NSArray arrayWithObjects:
@"初一", @"初二", @"初三", @"初四", @"初五", @"初六", @"初七", @"初八", @"初九", @"初十",
@"十一", @"十二", @"十三", @"十四", @"十五", @"十六", @"十七", @"十八", @"十九", @"二十",
@"廿一", @"廿二", @"廿三", @"廿四", @"廿五", @"廿六", @"廿七", @"廿八", @"廿九", @"三十", nil];
NSString* string;
if(month<10)
{
if (day < 10) {
string = [NSString stringWithFormat:@"%ld0%ld0%ld23",year,month,day];
}
else{
string = [NSString stringWithFormat:@"%ld0%ld%ld23",year,month,day];
}
}
else
{
if (day < 10) {
string = [NSString stringWithFormat:@"%ld%ld0%ld23",year,month,day];
}
else{
string = [NSString stringWithFormat:@"%ld%ld%ld23",year,month,day];
}
}
NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
[inputFormatter setDateFormat:@"yyyyMMddHH"];
NSDate* inputDate = [inputFormatter dateFromString:string];
NSCalendar *localeCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierChinese];
unsigned unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
NSDateComponents *localeComp = [localeCalendar components:unitFlags fromDate:inputDate];
NSString *d_str = [chineseDays objectAtIndex:localeComp.day-1];
return d_str;
}
网友评论