UIDatePicker timezone fix - Swift iOS

UIDatePicker timezone fix – Swift iOS

Convert time to different timezones

If you are working on UIDatePicker in your Swift project, you might come across a problem that when fetching the value from UIDatePicker it usually returns the value by mapping with your timezone. But we want to have the actual value from date picker as it is (without having timezone mapping). You can use the following function to get the actual value selected from date picker:

datepicker.date.description(with: .current)

Assuming datepicker is your outlet for type UIDatePicker. You can also prevent the user from selecting previous dates by writing the following line at the end of your viewDidLoad() function:

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    
    datepicker.minimumDate = Date()
}

Video tutorial:

Leave a Reply

Please disable your adblocker or whitelist this site!