最佳答案
我试图转换一个 NSDate
到一个 String
,然后改变格式。但是当我将 NSDate
传递给 String
时,它会产生空格。
let formatter = DateFormatter()
let myString = (String(describing: date))
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
let yourDate: Date? = formatter.date(from: myString)
formatter.dateFormat = "dd-MMM-yyyy"
print(yourDate)