DateFormatter对我很有意思:
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MM'/'DD'/'YYYY"
var dateString = "09/28/1989"
var date = dateFormatter.dateFromString(dateString)
println(date)
返回:
“可选(1988-12-24 13:00:00 +0000)”
任何形式的帮助都将受到赞赏。
答案 0 :(得分:2)
看起来您的日期格式化程序有点过时了。 "MM'/'DD'/'YYYY"
读取"Padded month / day of the year (not month) / year of the current week (so Jan 1-6 could overlap and add side-effects)"
我猜测你的目标是"MM'/'dd'/'yyyy"
,其内容为"Padded month / padded day of month / year"
作为参考,这里是当前使用的Unicode Technical Standard,Apple将其作为iOS 7+和OSX 10.9 + here
的标准。