如何将此 UNIX 纪元日期(以毫秒为单位)转换为本地 date/time?

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

我从服务器收到一些奇怪的东西 date/time。

如何转换"notification_date":1500461137000, 本地时间格式。

这是以毫秒为单位的 UNIX 纪元日期。除以1000后可以用timeIntervalSince1970换算。

let localDate = Date(timeIntervalSince1970: notificationDate / 1000)

对 Double 进行扩展并从您的通知日期转换。

 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)
   }
}