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.
精彩评论