I have a date "Thursday, 18 Sep 2014" in this format. when i click a "change date" button. how we can automatic select a this date in datepicker in swift language.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
var dateString = "Thursday, 18 Sep 2014"
var df = NSDateFormatter()
df.dateFormat = "eeee, dd MM yyyy"
var date = df.dateFromString(dateString)
if let unwrappedDate = date {
datePicker.setDate(unwrappedDate, animated: false)
}