function:
func date(person: String) -> String
{
let dateFormatter = DateFormatter()
let tempLocale = dateFormatter.locale // save locale temporarily
dateFormatter.locale = Locale(identifier: "en_US_POSIX") // set locale to reliable US_POSIX
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
let date = dateFormatter.date(from: person)!
//dateFormatter.dateFormat = "dd-MM-yyyy HH:mm:ss"
dateFormatter.dateFormat = "yyyy/MM/dd"
dateFormatter.locale = tempLocale // reset the locale
let dateString = dateFormatter.string(from: date)
// print("EXACT_DATE : \(dateString)")
return dateString
}
----------------------------------------------------------
Usage:
let datestring=date(person: "2017-01-27T18:36:36Z")
No comments:
Post a Comment