一个简单的计算获得的日期与现在的日期差
来源:互联网 发布:淘宝美工注意事项 编辑:程序博客网 时间:2024/05/22 18:52
-(NSString *)getDate:(NSString *)str{ NSString *date = [[NSString alloc]init]; int day = (int)[self getWeak:str]; if (day>0) { if (day>7) { NSArray *arr = [str componentsSeparatedByString:@"-"]; NSString *pMon = [arr objectAtIndex:1]; NSString *pDay = [arr objectAtIndex:2]; int mon = [pMon intValue]-1; NSArray *monArr = @[@"一月",@"二月",@"三月",@"四月",@"五月",@"六月",@"七月",@"八月",@"九月",@"十月",@"十一月",@"十二月"]; date = [NSString stringWithFormat:@"%@\n%@",pDay,[monArr objectAtIndex:mon]]; } else{ NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh-CN"]; [dateFormatter setDateFormat: @"yyyy.MM.dd.EEEE"]; NSDate *today = [NSDate date]; NSString *st = [dateFormatter stringFromDate:today]; NSArray *arr = [st componentsSeparatedByString:@"."]; NSString *pWeek = [arr objectAtIndex:3]; NSArray *arr1 = @[@"星期一",@"星期二",@"星期三",@"星期四",@"星期五",@"星期六",@"星期日"]; NSArray *arr2 = @[@"周一",@"周二",@"周三",@"周四",@"周五",@"周六",@"周日"]; NSArray *arr3 = @[@"下周一",@"下周二",@"下周三",@"下周四",@"下周五",@"下周六",@"下周日"]; for (int i=0; i<[arr1 count]; i++) { int a = 0; if ([pWeek isEqualToString:[arr1 objectAtIndex:i]]) { a = i; int dd = a+day; if (day==0) { date = @"今天"; }else if (day==1){ date = @"明天"; }else if (dd < 7) { date = [arr2 objectAtIndex:dd]; }else if (dd >= 7 && dd<14){ int w = dd%7; date = [arr3 objectAtIndex:w]; } } } } }else{ NSArray *arr = [str componentsSeparatedByString:@"-"]; NSString *pMon = [arr objectAtIndex:1]; NSString *pDay = [arr objectAtIndex:2]; int mon = [pMon intValue]-1; NSArray *monArr = @[@"一月",@"二月",@"三月",@"四月",@"五月",@"六月",@"七月",@"八月",@"九月",@"十月",@"十一月",@"十二月"]; date = [NSString stringWithFormat:@"%@\n%@",pDay,[monArr objectAtIndex:mon]]; } return date;}-(NSInteger)getWeak:(NSString *)time{ NSDate *today = [NSDate date]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat: @"yyyy-MM-dd"]; NSString *st = [dateFormatter stringFromDate:today]; NSDate *staDate = [dateFormatter dateFromString:st]; NSDateFormatter *dateFor = [[NSDateFormatter alloc] init]; [dateFor setDateFormat: @"yyyy-MM-dd"]; NSDate *endDate =[dateFor dateFromString:time]; NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSUInteger unitFlags = NSMonthCalendarUnit | NSDayCalendarUnit; NSDateComponents *components = [gregorian components:unitFlags fromDate:staDate toDate:endDate options:0]; NSInteger days = [components day]; return days;}
写的可能有些负责和啰嗦
getDate 这个方法中,传入的日期格式为 yyyy-MM-dd
0 0
- 一个简单的计算获得的日期与现在的日期差
- 计算日期的天数差
- Oracle日期函数:过去、现在及日期的差
- 【代码笔记】iOS-获得现在的日期
- 一个简单的JavaScript日期计算算法
- 一个简单的数学公式计算特殊日期
- 一段计算日期差的方法
- 计算两个日期的天数差
- 计算两个日期的天数差
- j2ME-计算两个日期的天数差
- asp中计算日期差的问题
- 计算日期差的JS代码
- asp 计算日期之间的差
- 计算两个时间的日期差
- 计算两个日期的天数之差
- 计算2个日期的差
- 计算两个日期的天数差
- js计算两个日期之间的差
- PGIS平台部署中的问题及解决方案
- Oracle11g启动关闭脚本
- jQuery选择器总结
- c#访问access 数据库
- 3 定义两个整型指针,分别用malloc、calloc对其分配空间保存3个元素,malloc分配的空间用memset清零,随机对数组进行赋值随机范围1-3,赋值后用memcmp比较两个数组。如果相同
- 一个简单的计算获得的日期与现在的日期差
- CP&SP
- Android Bug
- 修改MySQL数据库端口号 2.0
- openstack windows下远程debug调试(komodo)
- svn 更换IP eclipse 提交没有变更前的代码
- c#调用c语言dll,形参有char*
- ssh无密码远程登录-自己总结整理
- 在Ubuntu14.04上编写第一个GTK+3.