我有CoreData
myDate = date,Entity列并返回输出:
let mydate = coreDataValues[0].myDate!
print(mydate)
OUTPUT == 2017-02-01 12:45:40 +0000
我想将mydate
转换为datetime
,如下所示,例如
2017-12-20-23-59-59
我该怎么做?
泰
答案 0 :(得分:5)
你可以这样做:
var dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd-HH-mm-ss"
var date = dateFormatter.string(from: mydate as Date)
print(date)
OUTPUT = 2017-02-01-18-10-01