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

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -