Search code examples
swiftnsdateformatter

How to convert this UNIX epoch date in milliseconds to local date/time?


I am getting something strange date/time from server.

enter image description here

How to convert "notification_date": 1500461137000, to local time format.


Solution

  • This is a UNIX epoch date in milliseconds. You can convert it with timeIntervalSince1970 after dividing it by 1000.

    let localDate = Date(timeIntervalSince1970: notificationDate / 1000)