在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发布于 2017-02-02 00:32:31
DD是一年中的一天
dd是每月的某一天
如果有疑问,请检查Unicode reference
发布于 2017-02-02 00:32:45
DD是Day of year
dd是Day of the month
有关更多信息,请参见示例
http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns
发布于 2018-03-26 19:26:45
官方的Java文档是最终的参考:https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
D Day in year Number 189
d Day in month Number 10因为它不同于unicode引用:http://unicode.org/reports/tr35/tr35-dates.html#dfst-day
https://stackoverflow.com/questions/41984814
复制相似问题