为什么这个NSDateFormatter返回nil?

时间:2016-06-07 05:00:44

标签: swift nsdate nsdateformatter

为什么以下内容会返回nil

let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MM/dd"
let formattedDate = dateFormatter.dateFromString("2016-04-20 06:00:00 +0000")

1 个答案:

答案 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)