時間上不需要一個一個的獲取 可以用一個方法整體的獲取我們想要的時間還有星期的數(shù)據(jù)
- (void)createDataString{
NSArray * arrWeek=[NSArray arrayWithObjects:@"星期日",@"星期一",@"星期二",@"星期三",@"星期四",@"星期五",@"星期六", nil];
NSDate *date = [NSDate date];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *comps = [[NSDateComponents alloc] init];
NSInteger unitFlags = NSCalendarUnitYear |NSCalendarUnitMonth | NSCalendarUnitDay |NSCalendarUnitWeekday | NSCalendarUnitHour |NSCalendarUnitMinute |NSCalendarUnitSecond;
comps = [calendar components:unitFlags fromDate:date];
NSInteger week = [comps weekday];
NSInteger year=[comps year];
NSInteger month = [comps month];
NSInteger day = [comps day];
self.dateShowLabel.text=[NSString stringWithFormat:@"%ld年%ld月",year,month];
self.dayLabel.text=[NSString stringWithFormat:@"%ld",day];
self.weekShowLabel.text=[NSString stringWithFormat:@"%@",[arrWeek objectAtIndex:week]];
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者