开发者

Get the day position ... in Objective c

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜