If you do not want to enter several lines of code every time you want the date or time from the string U can copy the function below and use it as
let DateVar = DateTimeFrmSrgFnc("31/12/1990",FmtSrg: "dd/MM/yyyy") timePicker.setDate(DateVar, animated: false) func DateTimeFrmSrgFnc(DateSrgPsgVar: String, FmtSrg FmtSrgPsgVar: String)-> NSDate { // Format: "dd-MM-yyyy HH:mm:ss" let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = FmtSrgPsgVar return dateFormatter.dateFromString(DateSrgPsgVar)! }
source share