avatar

UIKit-DateFormatter

转载自:https://www.jianshu.com/p/2aa894e12080

Thursday, Mar 17, 2016

let dateFormate = DateFormatter()
dateFormate.dateFormat = "EEEE, MMM d, yyyy"
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)

03/17/2016

let dateFormate = DateFormatter()
dateFormate.dateFormat = "MM/dd/yyyy"
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)

03-17-2016 07:10

let dateFormate = DateFormatter()
dateFormate.dateFormat = "MM-dd-yyyy HH:mm"
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)

Mar 17, 7:10 AM

let dateFormate = DateFormatter()
dateFormate.dateFormat = "MMM d, H:mm a"
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)

March 2016

let dateFormate = DateFormatter()
dateFormate.dateFormat = "MMMM yyyy"
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)

17.03.16

let dateFormate = DateFormatter()
dateFormate.dateFormat = "dd.MM.yy"
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)

Mar 17, 2016

let dateFormate = DateFormatter()
dateFormate.dateFormat = "MMM d, yyyy"
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)

Thu, 17 Mar 2016 07:10:30 -0500

let dateFormate = DateFormatter()
dateFormate.dateFormat = "E, d MMM yyyy HH:mm:ss Z"
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)

2016-03-17T07:10:30-0500

let dateFormate = DateFormatter()
dateFormate.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)

NSDateFormatterStyle

3/17/16 (ShortStyle )

let dateFormate = DateFormatter()
dateFormate.dateStyle = .shortStyle
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)

Mar 17, 2016, 6:12:30 PM ( MediumStyle )

let dateFormate = DateFormatter()
dateFormate.dateStyle = .mediumStyle
dateFormate.timeStyle = .mediumStyle
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)

March 17, 2016 at 6:14:36 PM GMT+5:30 (LongStyle )

let dateFormate = DateFormatter()
dateFormate.dateStyle = .longStyle
dateFormate.timeStyle = .longStyle
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)

Thursday, March 17, 2016 (FullStyle)

let dateFormate = DateFormatter()
dateFormate.dateStyle = .fullStyle
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)
文章作者: X Mεl0n
文章链接: http://www.zrzz.site/2020/07/10/UIKit-DateFormatter/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 X Mεl0n | 随手记

评论