//时间转月 @"1992-12-22"
- (NSString *)timeWithMonth:(NSString *)time
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh-Hans"];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *date = [formatter dateFromString:time];
NSDateFormatter *ff = [[NSDateFormatter alloc] init];
ff.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh-Hans"];
NSArray *arr = ff.monthSymbols;
[ff setDateFormat:@"MM"];
NSInteger index = [[ff stringFromDate:date] integerValue];
NSString *month = [arr objectAtIndex:index-1];
NSDate *currentDate = [NSDate date];//获取当前时间,日期
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh-Hans"];
NSArray *arr2 = dateFormatter.monthSymbols;
[dateFormatter setDateFormat:@"MM"];
NSInteger index2 = [[dateFormatter stringFromDate:currentDate] integerValue];
NSString *month2 = [arr2 objectAtIndex:index2-1];
if ([month isEqualToString:month2]) { //比较当前时间
return @"本月";
}
return month2;
}