本文介绍了Swift:无法正确获取NSDate dateFormatter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DateFormatter对我来说很有趣:

DateFormatter is acting funny to me:

let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MM'/'DD'/'YYYY"
var dateString = "09/28/1989"
var date = dateFormatter.dateFromString(dateString)
println(date)

返回:

任何帮助将不胜感激。

推荐答案

看来您的日期格式化程序有点麻烦了。 MM'/'DD'/'YYYY 读取已填充月份/一年中的某天(而非月份)/当前周的某年(因此1月1-6日可能会重叠并增加副作用)

It looks like your date formatter is a bit off. "MM'/'DD'/'YYYY" reads "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 ,显示为每月的填充月份/每月的填充日期

I'm guessing that what you're aiming for is "MM'/'dd'/'yyyy", which reads "Padded month / padded day of month / year"

作为参考,这是当前使用的,Apple将其记录为iOS 7+和OSX 10.9+的标准

For reference, here's the currently-used Unicode Technical Standard that Apple documents as their standard for iOS 7+ and OSX 10.9+ here

这篇关于Swift:无法正确获取NSDate dateFormatter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-20 22:33