I know this is a repetitive query, but I am stuck up with this issue. I need to know how can I get the day like Mon,Tues for a particular date eg: 18 July, 2010 etc.
appreciate your help!!
I know this is a repetitive query, but I am stuck up with this issue. I need to know how can I get the day like Mon,Tues for a particular date eg: 18 July, 2010 etc.
appreciate your help!!
To print out the textual representation of a the day from and NSDate, try the following:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEEE"];
[dateFormatter release];
NSDate *myDate = [NSDate date];
NSString *day = [dateFormatter stringFromDate:myDate];
For more information on http://unicode.org/reports/tr35/tr35-10.html#Date_Format_Patterns
try this
NSDateFormatter* theDateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[theDateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[theDateFormatter setDateFormat:@"EEEE"];
NSString *weekDay = [theDateFormatter stringFromDate:[NSDate date]];
NSString *dateString = @"20 July, 2011"; // select this from your database
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"dd MMMM, yyyy"];
NSDate *date = [dateFormatter dateFromString:dateString];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [gregorian components:NSWeekdayCalendarUnit fromDate:date];
NSInteger weekday = [components weekday];
NSLog(@"%d", weekday);
Note that Sunday is 1.
2 would be Monday etc...
Edited my answer to show you an example of how to convert a string to an NSDate. ;)