iOS编程上获取本地时间以及星期几时间
十年的云城网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整云城建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联从事“云城网站设计”,“云城网站推广”以来,每个客户项目都认真落实执行。
本文回复一位网友关于获取时间的问题:http://blog.csdn.net/duxinfeng2010/article/details/8653411#reply
- (void)viewDidLoad { [super viewDidLoad]; NSInteger year,month,day,hour,min,sec,week; NSString *weekStr=nil; NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDate *now = [NSDate date];; NSDateComponents *comps = [[NSDateComponents alloc] init]; NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit; comps = [calendar components:unitFlags fromDate:now]; year = [comps year]; week = [comps weekday]; month = [comps month]; day = [comps day]; hour = [comps hour]; min = [comps minute]; sec = [comps second]; if(week==1) { weekStr=@"星期天"; }else if(week==2){ weekStr=@"星期一"; }else if(week==3){ weekStr=@"星期二"; }else if(week==4){ weekStr=@"星期三"; }else if(week==5){ weekStr=@"星期四"; }else if(week==6){ weekStr=@"星期五"; }else if(week==7){ weekStr=@"星期六"; } else { NSLog(@"error!"); } NSLog(@"现在是:%d年%d月%d日 %d时%d分%d秒 %@",year,month,day,hour,min,sec,weekStr); NSInteger Monday = day - week+1+1; for (int i=1; i<=7; i++) { NSLog(@"本周 星期%d :%d年%d月%d日 ",i,year,month,Monday); Monday=Monday+1; } }
运行结果:
当前文章:iOS编程上获取本地时间以及星期几时间
URL链接:http://hbruida.cn/article/gcccjp.html