UIDatePicker shows one year ahead in the UITextfield.inputview when using "MM/dd/YYYY" format.
@objc public func dateChange(datePicker: UIDatePicker) {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MM/dd/YYYY"
dateOfBirthVC.customView.entryTextField.text = dateFormatter.string(from: datePicker.date)
}
Below is the code to track the changes in date picker and display back in the UITextField
datePicker?.addTarget(self, action: #selector(ViewController.dateChange(datePicker:)), for: .valueChanged)
dateOfBirthVC.customView.entryTextField.inputView = datePicker
Here is the problem. When user change the date in the date picker, the year in the UITextfield shows one year after. That happened only when user put the month for December and the date between 25 and 31.