开发者

Get the day position ... in Objective c

开发者 https://www.devze.com 2023-03-04 13:19 出处:网络
How I can get the position of a day inside a week like: If it\'s sund开发者_如何转开发ay = 0 monday =1

How I can get the position of a day inside a week like:

If it's sund开发者_如何转开发ay = 0 monday =1 tuesday=2 ...

Thanks


You can try using NSCalendar for this:

NSArray *days = [NSArray arrayWithObjects:@"Sunday", @"Monday", @"Tuesday", @"Wednesday", @"Thursday", @"Friday", @"Saturday", nil];

NSDate *today = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc]
                         initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *weekdayComponents =
                    [gregorian components:NSWeekdayCalendarUnit fromDate:today];
NSInteger weekday = [weekdayComponents weekday] - 1;

NSLog(@"it is %@ today.", [days objectAtIndex:weekday]);

[gregorian release];


[NSDateFormatter weekdaySymbols] will return an NSArray of the weekday symbols.

0

精彩评论

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