-
(NSString *)distanceTimeWithBeforeTime:(double)beTime
{
NSTimeInterval now = [[NSDatedate]timeIntervalSince1970];
double distanceTime = now - beTime;
NSString * distanceStr;NSDate * beDate = [NSDatedateWithTimeIntervalSince1970:beTime];
NSDateFormatter * df = [[NSDateFormatteralloc]init];
[df setDateFormat:@"HH:mm"];
NSString * timeStr = [df stringFromDate:beDate];[df setDateFormat:@"dd"];
NSString * nowDay = [df stringFromDate:[NSDate date]];
NSString * lastDay = [df stringFromDate:beDate];if (distanceTime < 60) {//小于一分钟
distanceStr = @"刚刚";
}
else if (distanceTime <6060) {//时间小于一个小时
distanceStr = [NSString stringWithFormat:@"%ld分钟前",(long)distanceTime/60];
}
else if(distanceTime <246060 && [nowDayintegerValue] == [lastDay integerValue]){//时间小于一天
distanceStr = [NSString stringWithFormat:@"今天 %@",timeStr];
}
else if(distanceTime<2460602 && [nowDayintegerValue] != [lastDay integerValue]){if ([nowDay integerValue] - [lastDay integerValue] ==1 || ([lastDay integerValue] - [nowDayintegerValue] > 10 && [nowDayintegerValue] == 1)) { distanceStr = [NSString stringWithFormat:@"昨天 %@",timeStr];
}
else{
[df setDateFormat:@"MM-dd HH:mm"];
distanceStr = [df stringFromDate:beDate];
}}
else if(distanceTime <246060*365){
[df setDateFormat:@"MM-dd HH:mm"];
distanceStr = [df stringFromDate:beDate];
}
else{
[df setDateFormat:@"yyyy-MM-dd HH:mm"];
distanceStr = [df stringFromDate:beDate];
}
return distanceStr;
}
timeUtil
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 前言:iOS中把时间转化成“刚刚、几分钟前、几小时前、几天前、某月某日几点几分、.......”格式这就需要看后台...