Swift:无法获得NSDate dateFormatter

时间:2015-02-09 07:15:53

标签: ios date swift nsdate nsdateformatter

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)”

任何形式的帮助都将受到赞赏。

1 个答案:

答案 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

的标准。