Swift
Updated: 22nd October 2015
String to NSDate
var dateString="01-02-2010"var dateFormatter=NSDateFormatter()// this is imporant - we set our input date format to match our input stringdateFormatter.dateFormat="dd-MM-yyyy"// voila!var dateFromString=dateFormatter.dateFromString(dateString)
NSDate to String
var formatter:NSDateFormatter()formatter.dateFormat="dd-MM-yyyy"let stringDate:String=formatter.stringFromDate(NSDate())println(stringDate)
网友评论