为什么以下内容会返回nil
?
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MM/dd"
let formattedDate = dateFormatter.dateFromString("2016-04-20 06:00:00 +0000")
答案 0 :(得分:1)
您可以Date
: 04/20
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss ZZZZZ"
let Date = dateFormatter.dateFromString("2016-04-20 06:00:00 +0000")
dateFormatter.dateFormat = "MM/dd"
let newDate = dateFormatter.stringFromDate(Date!)
print(newDate)