1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| + (NSString *)getChineseYearWithDate:(NSDate *)date{ NSArray *chineseYears = [NSArray arrayWithObjects: @"甲子", @"乙丑", @"丙寅", @"丁卯", @"戊辰", @"己巳", @"庚午", @"辛未", @"壬申", @"癸酉", @"甲戌", @"乙亥", @"丙子", @"丁丑", @"戊寅", @"己卯", @"庚辰", @"辛巳", @"壬午", @"癸未", @"甲申", @"乙酉", @"丙戌", @"丁亥", @"戊子", @"己丑", @"庚寅", @"辛卯", @"壬辰", @"癸巳", @"甲午", @"乙未", @"丙申", @"丁酉", @"戊戌", @"己亥", @"庚子", @"辛丑", @"壬寅", @"癸卯", @"甲辰", @"乙巳", @"丙午", @"丁未", @"戊申", @"己酉", @"庚戌", @"辛亥", @"壬子", @"癸丑", @"甲寅", @"乙卯", @"丙辰", @"丁巳", @"戊午", @"己未", @"庚申", @"辛酉", @"壬戌", @"癸亥", nil]; NSCalendar *localeCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierChinese]; unsigned unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay; NSDateComponents *localeComp = [localeCalendar components:unitFlags fromDate:date]; NSString *y_str = [chineseYears objectAtIndex:localeComp.year - 1]; NSString *Cz_str = nil; if ([y_str hasSuffix:@"子"]) { Cz_str = @"鼠"; }else if ([y_str hasSuffix:@"丑"]){ Cz_str = @"牛"; }else if ([y_str hasSuffix:@"寅"]){ Cz_str = @"虎"; }else if ([y_str hasSuffix:@"卯"]){ Cz_str = @"兔"; }else if ([y_str hasSuffix:@"辰"]){ Cz_str = @"龙"; }else if ([y_str hasSuffix:@"巳"]){ Cz_str = @"蛇"; }else if ([y_str hasSuffix:@"午"]){ Cz_str = @"马"; }else if ([y_str hasSuffix:@"未"]){ Cz_str = @"羊"; }else if ([y_str hasSuffix:@"申"]){ Cz_str = @"猴"; }else if ([y_str hasSuffix:@"酉"]){ Cz_str = @"鸡"; }else if ([y_str hasSuffix:@"戌"]){ Cz_str = @"狗"; }else if ([y_str hasSuffix:@"亥"]){ Cz_str = @"猪"; } return [NSString stringWithFormat:@"%@(%@)年",y_str,Cz_str]; }
|