Jigen Jigen - 9 months ago 111
Swift Question

Convert date string swift

I have a date string in this format:


and I need to change it to something like this:


Previously I have always used this library -> SwiftDate to manipulate the dates, but it doesn't work now.

I tried also something like:

let myDate = self.dateNoteDict[indexPath.row]!
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss.SSSSxxx"
let date = dateFormatter.dateFromString(myDate)
print("date -> \(date)")

but it doesn't work. How can I do?

Thanks in advance.


The standard ISO8601 date format with fractional seconds and time zone is


let myDate = "2016-06-20T13:01:46.457+02:00"
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
let date = dateFormatter.dateFromString(myDate)!
dateFormatter.dateFormat = "dd/MM/yyyy"
let dateString = dateFormatter.stringFromDate(date)