Reputation: 2444
I am getting something strange date/time from server.
How to convert "notification_date": 1500461137000, to local time format.
Upvotes: 1
Views: 673
Reputation: 699
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)
}
}
Upvotes: 0
Reputation: 58049
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)
Upvotes: 4