如何在swift 2中更改date格式化程序?

我知道如何将date转换为string和stringdate的基本知识。 但是我面临以下问题:

dateAsString = "2016/12/31" 

我想将这个string转换 datestring格式,位置更改为12/31/2016

请帮忙

步骤1

 //Initial Conversion // create the date formater let dateFormatter = NSDateFormatter() // set the date format based on your Initial String dateFormatter.dateFormat = "yyyy/MM/dd" // Convert the string to date let date1 = dateFormatter.dateFromString("2016/12/31") 

第2步

 //Second Conversion you need the output like 12/31/2016 // set the date format based on your final output dateFormatter.dateFormat = "MM/dd/yyyy" // This is for convert the date to String let finalString = dateFormatter.StringFromDate(date1) // This is for convert the String to date let finalDate = dateFormatter.dateFromString(finalString)