处理美国时间 Tue May 31 17:46:55 +0800 2011

来源:互联网 发布:无标度网络特性 编辑:程序博客网 时间:2024/04/30 09:09
/** *  重写created_at的getter方法 */- (NSString *)created_at{    //create_at: Tue May 31 17:46:55 +0800 2011    //1.获得微博创建时间    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];    fmt.dateFormat = @"EEE MMM dd HH:mm:ss Z yyyy";    fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];    NSDate *createdDate = [fmt dateFromString:_created_at];        //2.判断创建时间和当前时间的差距    if (createdDate.isToday) { //今天        if (createdDate.deltaWithNow.hour >= 1) {            return [NSString stringWithFormat:@"%d小时前",createdDate.deltaWithNow.hour];        }else if (createdDate.deltaWithNow.minute >= 1){            return [NSString stringWithFormat:@"%d分钟前",createdDate.deltaWithNow.minute];        }else{            return @"刚刚";        }    }else if (createdDate.isYesterday){ //昨天        fmt.dateFormat = @"昨天 HH:mm";        return [fmt stringFromDate:createdDate];    }else if(createdDate.isToday){ //今年        fmt.dateFormat = @"MM-dd HH:mm";        return [fmt stringFromDate:createdDate];    }else{ //非今年        fmt.dateFormat = @"yyyy-MM-dd HH:mm";        return [fmt stringFromDate:createdDate];    }    }

0 0