本文回復(fù)一位網(wǎng)友關(guān)于獲取時間的問題: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(@"現(xiàn)在是:%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; } }
運行結(jié)果:
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。