I think you cannot DayName (like Sunday) with Year-Month-Day until you make it completely normal, but you can get the day with the date by following the code below. This will help you.
Snapping to the next two IBOutlet in Xib.
and binding method - (IBAction) GetDateWithDay with DatePicker with ValueChange attribute
in .h file
IBOutlet UIDatePicker* datePicker;
IBOutlet UILabel* lblDate;
in .m file
-(IBAction)GetDateWithDay
{
NSDate* dt = datePicker.date;
NSDateFormatter* df = [[[NSDateFormatter alloc]init]autorelease];
[df setDateFormat:@"yyyy-MM-dd"];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSInteger units = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit;
NSDateComponents *components = [calendar components:units fromDate:dt];
NSInteger year = [components year];
NSInteger day = [components day];
NSDateFormatter *weekDay = [[[NSDateFormatter alloc] init] autorelease];
[weekDay setDateFormat:@"EEEE"];
NSDateFormatter *calMonth = [[[NSDateFormatter alloc] init] autorelease];
[calMonth setDateFormat:@"MM"];
lblDate.text = [NSString stringWithFormat:@"%@, %i-%@-%i",[weekDay stringFromDate:dt], day, [calMonth stringFromDate:dt], year];
}
source
share