NSDate *date = [NSDate date];
NSString *title = @"";
NSCalendar *calendar = [NSCalendar currentCalendar];//日历
NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:date toDate:[NSDate date] options:0];
NSInteger year = [components year];
NSInteger month = [components month];
NSInteger day = [components day];
//三天以内更改显示格式
if (year == 0 && month == 0 && day < 3) {
if (day == 0) {
title = NSLocalizedString(@"今天",nil);
}else if (day == 1) {
title = NSLocalizedString(@"昨天",nil);
}else if (day == 2) {
title = NSLocalizedString(@"前天",nil);
}
}
计算时间
最新推荐文章于 2018-11-12 15:44:22 发布