Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to convert sqlite datetime to nsdate in swift?

My sqllite column is set as default value by current time stamp. Now i am trying to get the value using but exception raise when going to formate the value

BirthAt is the NSDate type

var date: String? = resultSet?.stringForColumn("date")!
if var date1 = date {
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MM/dd/yyyy"
var date: NSDate? = dateFormatter.dateFromString(date1)!
self.BirthAt = date!
}
Posted
Updated 18-Dec-17 22:59pm

1 solution

It helped me

public func getDateFromString(date: String?) -> NSDate? {
if var date1 = date {
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MM-yyyy-dd HH:mm:ss"
dateFormatter.timeZone = NSTimeZone(name: "UTC")
var date: NSDate? = dateFormatter.dateFromString(date1)
return date!
}
return nil
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900