Tuesday, May 9, 2017

Swift 3 Unix Time Stamp to Date



let timestamp: Double = 1489467795000

let date = Date(timeIntervalSince1970: timestamp/1000)
let formatter = DateFormatter()
formatter.dateFormat = "MMM dd, YYYY"
formatter.timeZone = TimeZone(abbreviation: "UTC")
formatter.locale = NSLocale.current

let updatedDateStr = formatter.string(from: date)   //"Mar 14, 2017"


Hope This post is useful. Feel free to comment incase of any queries.



No comments:

Post a Comment