/**
* 获取时间是今天,明天还是后天
*
* @param time 待转换的时间
*
* @return 今天,明天,后天
*/
* 获取时间是今天,明天还是后天
*
* @param time 待转换的时间
*
* @return 今天,明天,后天
*/
- (NSString
*)getDays:(NSDate
*)timeDate{
NSDate
*toDate = [NSDate
date];
NSCalendar *calender = [[NSCalendar alloc] initWithCalendarIdentifier:NSChineseCalendar];
NSDateComponents *comps_today = [calender components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:toDate];
NSDateComponents *comps_other = [calender components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:timeDate];
if (comps_today.year == comps_other.year &&
comps_today.month == comps_other.month &&
comps_today.day == comps_other.day) {
return @"今天";
}else if (comps_today.year == comps_other.year &&
comps_today.month == comps_other.month &&
(comps_today.day - comps_other.day) == -1 ){
return @"明天";
}else if (comps_today.year == comps_other.year &&
comps_today.month == comps_other.month &&
(comps_today.day - comps_other.day) == -2){
return @"后天";
}
return @"";
NSCalendar *calender = [[NSCalendar alloc] initWithCalendarIdentifier:NSChineseCalendar];
NSDateComponents *comps_today = [calender components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:toDate];
NSDateComponents *comps_other = [calender components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:timeDate];
if (comps_today.year == comps_other.year &&
comps_today.month == comps_other.month &&
comps_today.day == comps_other.day) {
return @"今天";
}else if (comps_today.year == comps_other.year &&
comps_today.month == comps_other.month &&
(comps_today.day - comps_other.day) == -1 ){
return @"明天";
}else if (comps_today.year == comps_other.year &&
comps_today.month == comps_other.month &&
(comps_today.day - comps_other.day) == -2){
return @"后天";
}
return @"";
}