So i have datepicker and label that displaying selected time, but i need to make it like that. For example, i selected 10:00 time and label should show 11:30 13:00 14:30. Whatever time you pick it should be 1.5h 3h 4.5h. What i have to do?
@IBOutlet weak var dateLabel: UILabel!
@IBOutlet weak var DPOne: UIDatePicker!
override func viewDidLoad() {
super.viewDidLoad()
hoursMinutes()
DPOne.addTarget(self, action: #selector(dateChanged), for: .valueChanged)
}
@objc func dateChanged() {
hoursMinutes()
}
func hoursMinutes() {
let DF = DateFormatter()
DF.timeStyle = .short
let strDate = DF.string(from: DPOne.date)
dateLabel.text = strDate
}
CodePudding user response:
Check these out: DPOne.date.addingTimeInterval(...)
https://developer.apple.com/documentation/foundation/date/1948745-addingtimeinterval