时间上不需要一个一个的获取 可以用一个方法整体的获取我们想要的时间还有星期的数据
- (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]];
}