【发布时间】:2015-01-02 13:04:29
【问题描述】:
从日期字符串中设置日期选择器日期的正确方法是什么
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "dd/MM/YY"
let convertedStartDate = dateFormatter.dateFromString("1/3/15")
startDatePicker.date = convertedStartDate!
这个不行,convertedStartDate = nil
【问题讨论】:
-
我相信,如果您将日期格式字符串更改为“d/M/YY”,您的格式化程序就会工作。通过提供两个
d's 和M's 你告诉它会有领先的0's 个位数的日期和月份。 -
我试过了。没有运气。并且肯定不会在大多数日期工作
-
好的。更简单的选择。使用
dateFormatter.dateStyle = .ShortStyle。这在操场上对我有用。
标签: swift datepicker