开发者

how to get a particular day of week in objective c?

开发者 https://www.devze.com 2022-12-28 10:05 出处:网络
Using the Gregorian calendar, I am able to get the number of the day of the week (i.e. 1 for Sunday and 2 for Monday, etc.) but I am not able to find a function that displays the name of week then the

Using the Gregorian calendar, I am able to get the number of the day of the week (i.e. 1 for Sunday and 2 for Monday, etc.) but I am not able to find a function that displays the name of week then the number. Can anyone help?

Here is my co开发者_JAVA技巧de to get the number of day:

NSDate *dates = [gregorian dateFromComponents:component];

NSDateComponents *weekdayComponents =[gregorian components:(NSDayCalendarUnit | NSWeekdayCalendarUnit) fromDate:dates];

NSUInteger *weekdays = [weekdayComponents weekday]; 


NSString *dayw=[NSString stringWithFormat:@"%1i",weekdays];

NSLog(@"%@",dayw);


Create an NSDateFormatter. The format string @"EEEE" will output the name of the day of the week.

0

精彩评论

暂无评论...
验证码 换一张
取 消