Iphone NSCalendar将在工作日显示

Iphone NSCalendar将在工作日显示,iphone,xcode,Iphone,Xcode,我使用NSCalendar来显示星期天,我可以用整数显示工作日,但我不知道如何让它告诉我工作日,即“星期四”。我读到%A和%A可能会这样做,但我不知道如何实现它们。我的代码如下 NSDate* now = [NSDate date]; NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents *weekdayComponents =[g

我使用NSCalendar来显示星期天,我可以用整数显示工作日,但我不知道如何让它告诉我工作日,即“星期四”。我读到%A和%A可能会这样做,但我不知道如何实现它们。我的代码如下

NSDate* now = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *weekdayComponents =[gregorian components:NSWeekdayCalendarUnit fromDate:now];
NSInteger weekday = [weekdayComponents weekday];
myLabel.text = [NSString stringWithFormat:@"%02d", weekday];
我使用myLabel在Iphone上显示字符串,但如果有更好的方法,请告诉我

谢谢你的帮助


James

要显示一周中的哪一天,您实际上需要使用
NSDateFormatter
类,将'EEEE'格式设置为获取全天名称(如星期四),或将'EEE'设置为缩短日期(如星期四)。非常简单的代码:

NSDateFormatter *f = [[NSDateFormatter alloc] init];
[f setDateFormat:@"EEEE"];
NSLog([f stringFromDate:[NSDate date]]);

要显示一周中的哪一天,您实际上需要使用
NSDateFormatter
类,将“EEEE”格式设置为获取全天名称(如星期四),或将“EEE”设置为缩短(如星期四)。非常简单的代码:

NSDateFormatter *f = [[NSDateFormatter alloc] init];
[f setDateFormat:@"EEEE"];
NSLog([f stringFromDate:[NSDate date]]);

你好如何获取工作日的整数值。即;假设周一是1,周二是2,周三是3,@sudheer,检查NSCalendar和NSDateComponent classesHi。如何获取工作日的整数值。即;假设周一是1,周二是2,周三是3,@sudheer,检查NSCalendar和NSDateComponent类