Possible Duplicate:
Objective C - How can i get the weekday from NSDate?
How do I get the day of the week using NSDate and show using NSLog?
I wonder the current day, such as today.
Ex: NSLog(@"the day is:",day)
Resp: "the day is: Monday"
Possible Duplicate:
Objective C - How can i get the weekday from NSDate?
How do I get the day of the week using NSDate and show using NSLog?
I wonder the current day, such as today.
Ex: NSLog(@"the day is:",day)
Resp: "the day is: Monday"
NSDateFormatter* day = [[NSDateFormatter alloc] init];
[day setDateFormat: @"EEEE"];
NSLog(@"the day is: %@", [day stringFromDate:[NSDate date]]);
Using NSDateComponents:
static inline NSString *stringFromWeekday(int weekday)
{
static NSString *strings[] = {
@"Sunday",
@"Monday",
@"Tuesday",
@"Wednesday",
@"Thursday",
@"Friday",
@"Saturday",
};
return strings[weekday - 1];
}
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSWeekdayCalendarUnit fromDate:[NSDate date]];
NSLog(@"%@", stringFromWeekday([components weekday]));
Of course, this doesn't respect locales & such.
NSLog(@"the day is: %@", [[NSDate date] descriptionWithCalendarFormat:@"%A" timeZone:nil locale:nil]);