在Quickift 3中是否破坏了DateFormatter类?

use*_*ond -5 nsdateformatter swift

我正在尝试使用Swift 3库提供的Date类.我不确定我做得对.当我打印日期时,它会打印正确的日期,但是当我尝试将其从日期转换为字符串时,它会将日期更改为其他日期.

let today = Date()
print(" Date object : \(today)")

let format = DateFormatter()
format.dateFormat = "mm/dd/yy"

print(" Date to String : \(format.string(from: today)")
Run Code Online (Sandbox Code Playgroud)

这给出了输出:

日期对象:2017-06-03 18:13:39 +0000

字符串日期:13/03/17

max*_*ax_ 5

mm是分钟的格式说明符,因此输出返回的原因,13而不是06您调用的时间(以分钟为单位)Date().

您需要使用它MM来显示月份.

有关更多信息,请参阅日期说明符的unicode报告:http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns