Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to get day of week from NSDate?

How to get day of week from NSDate?

Posted on Sep 8, 2008 5:08 PM

Reply
Question marked as Best reply

Posted on Sep 8, 2008 8:19 PM

something like this:


NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *weekdayComponents =[gregorian components:NSWeekdayCalendarUnit fromDate:dateOfInterest];
NSInteger weekday = [weekdayComponents weekday];
// weekday 1 = Sunday for Gregorian calendar
[gregorian release];
9 replies
Question marked as Best reply

Sep 8, 2008 8:19 PM in response to aapl.crox

something like this:


NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *weekdayComponents =[gregorian components:NSWeekdayCalendarUnit fromDate:dateOfInterest];
NSInteger weekday = [weekdayComponents weekday];
// weekday 1 = Sunday for Gregorian calendar
[gregorian release];

Sep 8, 2008 9:41 PM in response to aapl.crox

Here's a way to get the name of the weekday as an NSString if you've already got an NSDate...

NSDate * testDate = [NSDate date];
NSString * weekdayString = [testDate descriptionWithCalendarFormat:@"%A" timeZone:nil
locale:[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]];
NSLog(@"Day of the week: %@", weekdayString);

The output is something like:

Day of the week: Monday

You can use a lower-case "%a" as the descriptionWithCalendarFormat if you just want the three character weekday abbreviation ("Mon", "Tue", "Wed", etc).

Steve

How to get day of week from NSDate?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.