DateFormat.date(from:) always returns nil

时间:2018-09-18 20:36:13

标签: swift nsdate nsdateformatter optional

I am trying to get a time to set in a DatePicker. I want a date that has the format "HH:mm". This is my current code:

let dateFormatter = DateFormatter()
dateFormatter.dateFormat =  "HH:mm"
let date = dateFormatter.date(from: "09:00")
print(String(describing: date))
picker.date = date!

However date is always nil. Where am I going wrong? Thanks.

0 个答案:

没有答案