+(NSString *)getUTCFormateDate:(NSString *)newsDate
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSLog(@"newsDate = %@",newsDate);
NSDate *newsDateFormatted = [dateFormatter dateFromString:newsDate];
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
[dateFormatter setTimeZone:timeZone];
NSDate* current_date = [[NSDate alloc] init];
NSTimeInterval time=[current_date timeIntervalSinceDate:newsDateFormatted];//间隔的秒数
int year =((int)time)/(3600*24*30*12);
int month=((int)time)/(3600*24*30);
int days=((int)time)/(3600*24);
int hours=((int)time)%(3600*24)/3600;
int minute=((int)time)%(3600*24)/60;
NSLog(@"time=%f",(double)time);
NSString *dateContent;
if (year!=0) {
dateContent = newsDate;
}else if(month!=0){
dateContent = [NSString stringWithFormat:@"%@%i%@",@" ",month,@"个月前"];
}else if(days!=0){
dateContent = [NSString stringWithFormat:@"%@%i%@",@" ",days,@"天前"];
}else if(hours!=0){
dateContent = [NSString stringWithFormat:@"%@%i%@",@" ",hours,@"小时前"];
}else {
dateContent = [NSString stringWithFormat:@"%@%i%@",@" ",minute,@"分钟前"];
}
return dateContent;
}
网友评论