IOS 获取格式化后的时间(今天|昨天|前天)

2016-09-03  本文已影响43人  蜗牛1992
+(NSString *)GetFormatTime:(long64)llTime
{
    NSDateFormatter *pFormatter = [[NSDateFormatter alloc]init];
    
    long64 time = [[NSDate date]timeIntervalSince1970];
    long64 llMissTiming = time-llTime/1000;
    NSDate *pDate = [NSDate dateWithTimeIntervalSince1970:(llTime)/1000];
    
    if (llMissTiming >=0 && llMissTiming <= 60*60*24) {
        [pFormatter setDateFormat:@"今天 HH:mm"];
    }else if (llMissTiming >= 60*60*24 && llMissTiming <=60*60*24*2){
        [pFormatter setDateFormat:@"昨天 HH:mm"];
    }else if (llMissTiming >= 60*60*24*2 && llMissTiming <= 60*60*24*3){
        [pFormatter setDateFormat:@"前天 HH:mm"];
    }else if (llMissTiming >= 60*60*24*3 && llMissTiming <= 60*60*24*7)
        [pFormatter setDateFormat:@"EE HH:mm"];
    else{
        [pFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    }
    return [pFormatter stringFromDate:pDate];
}
上一篇下一篇

猜你喜欢

热点阅读