时间戳2016-4-29转成月份

//时间转月 @"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;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容