objective-cxcodemacosnsdatepicker

Display time only from datepicker


I have a NSDatePicker and am trying to get only the hour...can this done? The web references to setting:

datePicker.datePickerMode = UIDatePickerModeTime;

but I don't see that option anywhere - it appears to be an iOS only feature. How can I do this for a desktop cocoa based app?


Solution

  • Use the NSDatePickerElementFlags, which you set for your picker using setDatePickerElements:

    [datePicker setDatePickerElements:NSHourMinuteSecondDatePickerElementFlag];
    

    or

    [datePicker setDatePickerElements:NSHourMinuteDatePickerElementFlag];