Search code examples
iphoneiosios5ios4

How to get the particaular day of week in a dropdown when the user selects a date from date picker?


How to get the particaular day of week from a dropdown when the user selects a date from date picker??

I want to let the user select a date drom datepicker. And in the next button i have day field where it contains list of days in a week.

I want to show the particular day for selected date from datepicker when the user clicks on day button. Plz help me?????


Solution

  • Try this

    NSDate *today=calendarPicker.date;
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    
    NSDateComponents *components = [gregorian components: (NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate: today];
    
    components.year = [textfield.text intValue]; // Here value for year is fetched from a text field control. Similarly other values like month, date, hour or minute can be changed.
    
    [calendarPicker setDate: [calendar dateFromComponents:components] ]; // Update the date picker control.
    
    [calendar release];