how can I convert this date format in swift? -
i want convert wed jul 01 04:48:51 +0000 2015
2015-07-01
tried below could't execute well(returned nil).
let d = "wed jul 01 04:48:51 +0000 2015" let formatter = nsdateformatter() formatter.dateformat = "yyyy-mm-dd" let date: nsdate? = formatter.datefromstring(d)
is possible convert date format?
let d = "wed jul 01 04:48:51 +0000 2015" let formatter = nsdateformatter() formatter.dateformat = "eee mmm dd hh:mm:ss z yyyy" if let date = formatter.datefromstring(d) { formatter.dateformat = "yyyy-mm-dd" let datestring = formatter.stringfromdate(date) println(datestring) // "2015-07-01" }
Comments
Post a Comment