ios - Swift 2.1 DatePicker setDate does not set date to current day and specified time -


i trying set minimum date current day on date picker , sake of user experience, set time 7pm or 19:00. reason doesn't seem working. minimum date setting works time doesn't set. if remove minimum date line, time gets set 7pm, strangely, date gets set monday, jan 1. isn't year.

here's code below:

    datepicker.minimumdate = nsdate()     let calendar:nscalendar = nscalendar.currentcalendar()     let components = calendar.components([nscalendarunit.hour, nscalendarunit.minute], fromdate: nsdate())     components.hour = 19     components.minute = 00     datepicker.setdate(calendar.datefromcomponents(components)!, animated: true) 

what doing wrong here?

split last line into:

let date = calendar.datefromcomponents(components)! datepicker.setdate(date, animated: true) 

then @ value of date. you'll find january 1, 2000 @ desired time.

fix adding year, month, , day components to:

let components = calendar.components([nscalendarunit.hour, nscalendarunit.minute], fromdate: nsdate()) 

in other words, need:

let components = calendar.components([nscalendarunit.year, nscalendarunit.month, nscalendarunit.day, nscalendarunit.hour, nscalendarunit.minute], fromdate: nsdate()) 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -