获取当前日期和星期 iOS
2016-05-13 12:09
609 查看
//获取日期
NSArray * arrWeek=[NSArrayarrayWithObjects:@"星期日",@"星期一",@"星期二",@"星期三",@"星期四",@"星期五",@"星期六",nil];
//获取当前日期
NSDate *date0 = [NSDatedate];
//获取明天日期
NSDate *date1 = [NSDatedateWithTimeInterval:86400sinceDate:date0];
//获取后天日期
NSDate *date2 = [NSDatedateWithTimeInterval:86400sinceDate:date1];
NSCalendar *calendar = [[NSCalendaralloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
//设置时区
calendar.locale = [[NSLocalealloc] initWithLocaleIdentifier:@"ZH_cn"];
NSDateComponents *comps = [[NSDateComponentsalloc] init];
NSInteger unitFlags = NSCalendarUnitYear |
NSCalendarUnitMonth |
NSCalendarUnitDay |
NSCalendarUnitWeekday |
NSCalendarUnitHour |
NSCalendarUnitMinute |
NSCalendarUnitSecond;
comps = [calendar components:unitFlagsfromDate:date0];
NSInteger week0 = [comps weekday];
NSInteger year0 =[comps year];
NSInteger month0 = [comps month];
NSInteger day0 = [comps day];
NSString *str0 = [NSStringstringWithFormat:@"%zi-%zi-%zi %@",year0,month0,day0,[arrWeekobjectAtIndex:(week0
- 1)]];
comps = [calendar components:unitFlagsfromDate:date1];
NSInteger week1 = [comps weekday];
NSInteger year1=[comps year];
NSInteger month1 = [comps month];
NSInteger day1 = [comps day];
NSString *str1 = [NSStringstringWithFormat:@"%zi-%zi-%zi %@",year1,month1,day1,[arrWeekobjectAtIndex:(week1
-1)]];
comps = [calendar components:unitFlagsfromDate:date2];
NSInteger week2 = [comps weekday];
NSInteger year2=[comps year];
NSInteger month2 = [comps month];
NSInteger day2 = [comps day];
NSString *str2 = [NSStringstringWithFormat:@"%zi-%zi-%zi %@",year2,month2,day2,[arrWeekobjectAtIndex:(week2
-1)]];
NSArray * arrWeek=[NSArrayarrayWithObjects:@"星期日",@"星期一",@"星期二",@"星期三",@"星期四",@"星期五",@"星期六",nil];
//获取当前日期
NSDate *date0 = [NSDatedate];
//获取明天日期
NSDate *date1 = [NSDatedateWithTimeInterval:86400sinceDate:date0];
//获取后天日期
NSDate *date2 = [NSDatedateWithTimeInterval:86400sinceDate:date1];
NSCalendar *calendar = [[NSCalendaralloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
//设置时区
calendar.locale = [[NSLocalealloc] initWithLocaleIdentifier:@"ZH_cn"];
NSDateComponents *comps = [[NSDateComponentsalloc] init];
NSInteger unitFlags = NSCalendarUnitYear |
NSCalendarUnitMonth |
NSCalendarUnitDay |
NSCalendarUnitWeekday |
NSCalendarUnitHour |
NSCalendarUnitMinute |
NSCalendarUnitSecond;
comps = [calendar components:unitFlagsfromDate:date0];
NSInteger week0 = [comps weekday];
NSInteger year0 =[comps year];
NSInteger month0 = [comps month];
NSInteger day0 = [comps day];
NSString *str0 = [NSStringstringWithFormat:@"%zi-%zi-%zi %@",year0,month0,day0,[arrWeekobjectAtIndex:(week0
- 1)]];
comps = [calendar components:unitFlagsfromDate:date1];
NSInteger week1 = [comps weekday];
NSInteger year1=[comps year];
NSInteger month1 = [comps month];
NSInteger day1 = [comps day];
NSString *str1 = [NSStringstringWithFormat:@"%zi-%zi-%zi %@",year1,month1,day1,[arrWeekobjectAtIndex:(week1
-1)]];
comps = [calendar components:unitFlagsfromDate:date2];
NSInteger week2 = [comps weekday];
NSInteger year2=[comps year];
NSInteger month2 = [comps month];
NSInteger day2 = [comps day];
NSString *str2 = [NSStringstringWithFormat:@"%zi-%zi-%zi %@",year2,month2,day2,[arrWeekobjectAtIndex:(week2
-1)]];
相关文章推荐
- Google发布Gboard,一个iOS输入法,让你不用浏览器也能搜索
- ios之音频系列
- iOS tableView动态创建分组及组内排序
- IOS 使用AES/ECB/PKCS7Padding 加密、解密数据
- iOS关于小数点的四舍五入
- iOS开发企业版ipa分发
- (最新)iOS后台运行时间
- iOS Xcode 自带crash 崩溃问题的追踪方法
- iOS在xib或storyboard里为控件添加圆角、外框和外框颜色
- iOS自定义转场详解02——实现Keynote中的神奇移动效果
- iOS 支付宝支付开发集成流程,这里记载的是签名保存在前台的集成,
- ios 改变tableviewcell 的选中颜色
- iOS自定义转场详解03——实现通过圆圈放大缩小的转场动画
- iOS 自定义下拉线条动画
- iOS TextFiled 文本密码切换 光标偏移解决
- 谈谈iOS中粘性动画以及果冻效果的实现
- GCD 深入理解(二)
- ios socket 实现简单的聊天系统
- GCD 深入理解(一)
- iOS7 通过jsContext调用js交互问题