UIDatePicker value does not match displayed date

I encounter a weird issue if I set the maximum date of a UIDatePicker whenever I change the day on the UI, the value is always day – 1
I am doing something wrong ?

class DateField: UITextField {

private let datePicker = UIDatePicker()

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)

    datePicker.datePickerMode = .Date
    datePicker.maximumDate = NSDate()
    datePicker.addTarget(self, action: "updateBirthdate", forControlEvents: .ValueChanged)
    inputView = datePicker
    // inputAccessoryView stuff

func updateBirthdate() {
    text = NSDateFormatter.myFormatter().stringFromDate(datePicker.date)

Source: ios

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.