I have a UIDatePicker set in time mode, and have a property referencing that date picker. I don't know how to extract hour and minutes components from UIDatePicker when set to time mode in Swift 3. Please help
Even in .time
mode the date
property returns a Date
instance.
Get hour and minute with Calendar
and DateComponents
let picker = UIDatePicker()
picker.datePickerMode = .time
let date = picker.date
let components = Calendar.current.dateComponents([.hour, .minute], from: date)
let hour = components.hour!
let minute = components.minute!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With