Swift - 日期格式(DD vs dd)

JDM*_*JDM 1 nsdateformatter ios swift

在DateFormatter中使用DD和dd有什么区别?搜索时,我没有看到明显的差异..某些日期格式文档显示"DD"和"dd",有些则没有..

我想了解它的不同之处以及它产生以下评论中显示的结果的原因:

let formatter = DateFormatter()

formatter.dateFormat = "MM/DD/YYYY"
print(formatter.string(from: Date())) // 02/32/2017

formatter.dateFormat = "MM/dd/YYYY"
print(formatter.string(from: Date())) // 02/01/2017
Run Code Online (Sandbox Code Playgroud)

Sul*_*han 7

DD是一年
dd中的某一天是一个月中的某一天

如有疑问,请检查Unicode参考


luk*_*302 5

DDDay of year
dd是 是Day of the month

有关更多信息,请参见例如
http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns