关于DateFormater

一、关于时间的解析

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ssZ"
//dateFormatter.timeZone = TimeZone.current
//dateFormatter.locale = Locale.current
let date = dateFormatter.date(from: "2020-06-18 15:03:08+0800")!
print(date)
print(dateFormatter.string(from: date))
print(dateFormatter.string(from: Date()))

 可以参考:

Wednesday, Sep 12, 2018           --> EEEE, MMM d, yyyy
09/12/2018                        --> MM/dd/yyyy
09-12-2018 14:11                  --> MM-dd-yyyy HH:mm
Sep 12, 2:11 PM                   --> MMM d, h:mm a
September 2018                    --> MMMM yyyy
Sep 12, 2018                      --> MMM d, yyyy
Wed, 12 Sep 2018 14:11:54 +0000   --> E, d MMM yyyy HH:mm:ss Z
2018-09-12T14:11:54+0000          --> yyyy-MM-dd'T'HH:mm:ssZ
12.09.18                          --> dd.MM.yy
10:41:02.112                      --> HH:mm:ss.SSS

 

posted @ 2020-06-18 15:08  兜兜有糖的博客  阅读(534)  评论(1编辑  收藏  举报