dark knight dark knight - 1 year ago 261
iOS Question

How to convert milliseconds to date string in swift 3

I am trying to convert milliseconds to date string in swift 3,i tried by setting date fomatter but i am not getting current date string.

var milliseconds=1477593000000

let date = NSDate(timeIntervalSince1970: TimeInterval(milliseconds))
let formatter = DateFormatter()
formatter.dateFormat = "dd-MM-yyyy HH:mm:ss"
formatter.locale = NSLocale(localeIdentifier: "en_US") as Locale!
print(formatter.string(from: date as Date))


22-01-48793 01:30:00

Answer Source

Try this,

var date = Date(timeIntervalSince1970: (1477593000000 / 1000.0))
print("date - \(date)")

You will get output as date :

date - 2016-10-27 18:30:00 +0000

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download