iOS Developer Library

Developer

UIKit Framework Reference UIDatePicker Class Reference

Options
Deployment Target:

On This Page
Language:

UIDatePicker

Inherits From


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 2.0 and later

The UIDatePicker class implements an object that uses multiple rotating wheels to allow users to select dates and times. iPhone examples of a date picker are the Timer and Alarm (Set Alarm) panes of the Clock application. You may also use a date picker as a countdown timer.

When properly configured, a UIDatePicker object sends an action message when a user finishes rotating one of the wheels to change the date or time; the associated control event is UIControlEventValueChanged. A UIDatePicker object presents the countdown timer but does not implement it; the application must set up an NSTimer object and update the seconds as they’re counted down.

UIDatePicker does not inherit from UIPickerView, but it manages a custom picker-view object as a subview.

For more information about appearance and behavior configuration, see Date Pickers.

  • calendar calendar Property

    The calendar to use for the date picker.

    Declaration

    Swift

    @NSCopying var calendar: NSCalendar!

    Objective-C

    @property(nonatomic, copy) NSCalendar *calendar

    Discussion

    The default value of this property corresponds to the user’s current calendar as configured in Settings. This is equivalent to the value returned by calling the NSCalendar class method currentCalendar. Setting calendar to nil is equivalent to setting it to its default value.

    Calendars specify the details of cultural systems used for reckoning time; they identify the beginning, length, and divisions of a year.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later

    See Also

    locale
    timeZone

  • date date Property

    The date displayed by the date picker.

    Declaration

    Swift

    var date: NSDate

    Objective-C

    @property(nonatomic, retain) NSDate *date

    Discussion

    The default is the date when the UIDatePicker object is created. The date is ignored in the mode UIDatePickerModeCountDownTimer; for that mode, the date picker starts at 0:00. Setting this property does not animate the date picker by spinning the wheels to the new date and time; to do that you must use the setDate:animated: method.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later

  • locale locale Property

    The locale used by the date picker.

    Declaration

    Swift

    var locale: NSLocale?

    Objective-C

    @property(nonatomic, retain) NSLocale *locale

    Discussion

    The default value is the current locale as returned by the currentLocale property of NSLocale, or the locale used by the date picker’s calendar. Locales encapsulate information about facets of a language or culture, such as the way dates are formatted.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later

    See Also

    calendar
    timeZone

  • Sets the date to display in the date picker, with an option to animate the setting.

    Declaration

    Swift

    func setDate(_ date: NSDate, animated animated: Bool)

    Objective-C

    - (void)setDate:(NSDate *)date animated:(BOOL)animated

    Parameters

    date

    An NSDate object representing the new date to display in the date picker.

    animated

    YEStrue to animate the setting of the new date, otherwise NOfalse. The animation rotates the wheels until the new date and time is shown under the highlight rectangle.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later

    See Also

    date

  • timeZone timeZone Property

    The time zone reflected in the date displayed by the date picker.

    Declaration

    Swift

    var timeZone: NSTimeZone?

    Objective-C

    @property(nonatomic, retain) NSTimeZone *timeZone

    Discussion

    The default value is nil. which tells the date picker to use the current time zone as returned by localTimeZone (NSTimeZone) or the time zone used by the date picker’s calendar.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later

    See Also

    calendar
    locale

  • The mode of the date picker.

    Declaration

    Swift

    var datePickerMode: UIDatePickerMode

    Objective-C

    @property(nonatomic) UIDatePickerMode datePickerMode

    Discussion

    The value of this property indicates the mode of a date picker. It determines whether the date picker allows selection of a date, a time, both date and time, or a countdown time. The default mode is UIDatePickerModeDateAndTime. See Date Picker Mode for a list of mode constants.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later

  • The maximum date that a date picker can show.

    Declaration

    Swift

    var maximumDate: NSDate?

    Objective-C

    @property(nonatomic, retain) NSDate *maximumDate

    Discussion

    The property is an NSDate object or nil (the default), which means no maximum date. This property, along with the minimumDate property, lets you specify a valid date range. If the minimum date value is greater than the maximum date value, both properties are ignored. The minimum and maximum dates are also ignored in the countdown-timer mode (UIDatePickerModeCountDownTimer).

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later

  • The minimum date that a date picker can show.

    Declaration

    Swift

    var minimumDate: NSDate?

    Objective-C

    @property(nonatomic, retain) NSDate *minimumDate

    Discussion

    The property is an NSDate object or nil (the default), which means no minimum date. This property, along with the maximumDate property, lets you specify a valid date range. If the minimum date value is greater than the maximum date value, both properties are ignored. The minimum and maximum dates are also ignored in the countdown-timer mode (UIDatePickerModeCountDownTimer).

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later

  • The interval at which the date picker should display minutes.

    Declaration

    Swift

    var minuteInterval: Int

    Objective-C

    @property(nonatomic) NSInteger minuteInterval

    Discussion

    You can use this property to set the interval displayed by the minutes wheel (for example, 15 minutes). The interval value must be evenly divided into 60; if it is not, the default value is used. The default and minimum values are 1; the maximum value is 30.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later

  • The seconds from which the countdown timer counts down.

    Declaration

    Swift

    var countDownDuration: NSTimeInterval

    Objective-C

    @property(nonatomic) NSTimeInterval countDownDuration

    Discussion

    The NSTimeInterval value of this property indicates the seconds from which the date picker in countdown-timer mode counts down. If the mode of the date picker is not UIDatePickerModeCountDownTimer, this value is ignored. The default value is 0.0 and the maximum value is 23:59 (86,399 seconds).

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later

  • The mode of the date picker.

    Declaration

    Swift

    enum UIDatePickerMode : Int { case Time case Date case DateAndTime case CountDownTimer }

    Objective-C

    typedef enum { UIDatePickerModeTime, UIDatePickerModeDate, UIDatePickerModeDateAndTime, UIDatePickerModeCountDownTimer } UIDatePickerMode;

    Constants

    • Time

      UIDatePickerModeTime

      The date picker displays hours, minutes, and (optionally) an AM/PM designation. The exact items shown and their order depend upon the locale set. An example of this mode is [ 6 | 53 | PM ].

      Available in iOS 2.0 and later

    • Date

      UIDatePickerModeDate

      The date picker displays months, days of the month, and years. The exact order of these items depends on the locale setting. An example of this mode is [ November | 15 | 2007 ].

      Available in iOS 2.0 and later

    • DateAndTime

      UIDatePickerModeDateAndTime

      The date picker displays dates (as unified day of the week, month, and day of the month values) plus hours, minutes, and (optionally) an AM/PM designation. The exact order and format of these items depends on the locale set. An example of this mode is [ Wed Nov 15 | 6 | 53 | PM ].

      Available in iOS 2.0 and later

    • CountDownTimer

      UIDatePickerModeCountDownTimer

      The date picker displays hour and minute values, for example [ 1 | 53 ]. The application must set a timer to fire at the proper interval and set the date picker as the seconds tick down.

      Available in iOS 2.0 and later

    Discussion

    The mode determines whether dates, times, or both dates and times are displayed. You can also use it to specify the appearance of a countdown timer. You can set and retrieve the mode value through the datePickerMode property.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later