1

I am getting something strange date/time from server.

enter image description here

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

iDeveloper
  • 2,339
  • 2
  • 24
  • 38
  • 2
    Possible duplicate of [Swift convert unix time to date and time](https://stackoverflow.com/questions/26849237/swift-convert-unix-time-to-date-and-time) – NSNoob Jul 19 '17 at 11:49

2 Answers2

4

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)
Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
0

Do an extension on Double and convert from your notification date.

 Double(notificationDate).convertEpochTime()
 ...
 extension Double {
    func convertEpochTime() -> String{
       let readableDate = Date(timeIntervalSince1970: self / 1000.0)

       let dateFormatter = DateFormatter()
       dateFormatter.dateStyle = .medium
       dateFormatter.dateFormat = "EEEE, MMM d"

       return dateFormatter.string(from: readableDate)
   }
}
arvinq
  • 656
  • 6
  • 12