Swift: Convert Int into Date

Viewed 2956

I have an Int that I'm trying to convert into a date with a format of mm-dd-yyyy.

var dateTime = 1545215400000

let timeInterval = Double(dateTime)
let myNSDate = Date(timeIntervalSince1970: timeInterval) //Says its "Oct 29, 52338 at 6:00 AM"
print(myNSDate) //prints out 52338-10-29 10:00:00 +0000

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"

let date = dateFormatter.date(from: "\(timeInterval)") prints out nil

The date is completely wrong because the article for this date came out today. Any help would be appreciated!

0 Answers
Related