Swift: 无法正确获取 NSDate dateFormatter
Swift: can't get NSDate dateFormatter right
DateFormatter 对我来说很有趣:
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MM'/'DD'/'YYYY"
var dateString = "09/28/1989"
var date = dateFormatter.dateFromString(dateString)
println(date)
Returns:
"Optional(1988-12-24 13:00:00 +0000)"
我们将不胜感激。
您的日期格式化程序似乎有点问题。 "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 that Apple documents as their standard for iOS 7+ and OSX 10.9+ here
DateFormatter 对我来说很有趣:
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MM'/'DD'/'YYYY"
var dateString = "09/28/1989"
var date = dateFormatter.dateFromString(dateString)
println(date)
Returns:
"Optional(1988-12-24 13:00:00 +0000)"
我们将不胜感激。
您的日期格式化程序似乎有点问题。 "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 that Apple documents as their standard for iOS 7+ and OSX 10.9+ here