日期判断是今天/明天/后天
来源:互联网 发布:所有网络命令 编辑:程序博客网 时间:2024/05/21 17:31
/**
* 获取时间是今天,明天还是后天
*
* @param time 待转换的时间
*
* @return 今天,明天,后天
*/
* 获取时间是今天,明天还是后天
*
* @param time 待转换的时间
*
* @return 今天,明天,后天
*/
- (NSString*)getDays:(NSDate*)timeDate{
NSDate*toDate = [NSDatedate];
NSCalendar *calender = [[NSCalendaralloc]initWithCalendarIdentifier:NSChineseCalendar];
NSDateComponents *comps_today = [calendercomponents:(NSYearCalendarUnit| NSMonthCalendarUnit |NSDayCalendarUnit)fromDate:toDate];
NSDateComponents *comps_other = [calendercomponents:(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 @"今天";
}elseif(comps_today.year== comps_other.year&&
comps_today.month== comps_other.month&&
(comps_today.day- comps_other.day) == -1){
return @"明天";
}elseif(comps_today.year== comps_other.year&&
comps_today.month== comps_other.month&&
(comps_today.day- comps_other.day) == -2){
return @"后天";
}
return @"";
NSCalendar *calender = [[NSCalendaralloc]initWithCalendarIdentifier:NSChineseCalendar];
NSDateComponents *comps_today = [calendercomponents:(NSYearCalendarUnit| NSMonthCalendarUnit |NSDayCalendarUnit)fromDate:toDate];
NSDateComponents *comps_other = [calendercomponents:(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 @"今天";
}elseif(comps_today.year== comps_other.year&&
comps_today.month== comps_other.month&&
(comps_today.day- comps_other.day) == -1){
return @"明天";
}elseif(comps_today.year== comps_other.year&&
comps_today.month== comps_other.month&&
(comps_today.day- comps_other.day) == -2){
return @"后天";
}
return @"";
}
0 0
- 日期判断是今天/明天/后天
- 判断日期是昨天,今天,明天,后天,其他的显示星期
- java根据日期判断 前天,昨天,今天,明天,后天.
- 根据选择的日期字符串判断今天明天后天
- 判断日期是今天,昨天还是明天
- 判断日期是否是明天,今天,昨天
- php-今天明天后天判断解决
- js 根据已知的时间,判断是否是今天,明天,昨天,后天
- 今天明天后天
- [代码分享]判断日期是今天,昨天还是明天
- iOS开发 判断日期是今天,昨天还是明天
- IOS判断日期是今天,昨天还是明天
- js获取日期、前天、昨天、今天、明天、后天代码实例
- js获取日期:前天、昨天、今天、明天、后天
- js获取日期:前天、昨天、今天、明天、后天
- js_获取日期:前天、昨天、今天、明天、后天
- 根据js获取日期:前天、昨天、今天、明天、后天
- js获取日期:昨天今天和明天、后天
- Hbase配置安装
- 在Frame中对Graphics类的应用
- Unity 之 Light : Light Probe
- Git使用技巧大全和技巧
- Android几种弹窗的实现
- 日期判断是今天/明天/后天
- iOS之动态热修复技术JSPatch(一)
- 关于struts2 404 action找不到问题
- WinDgb命令 持续更新
- make 2>&1 | tee log.txt之小析
- Open vSwitch(OvS)源代码分析之工作流程(flow流表查询)
- 跟我一起写 Makefile
- STM32——I2C
- maven项目加载本地jar包的问题