I am retrieving information from an api and I am retrieving a value which holds a time, but the time looks like this, 1469880000
I did some research and realized that this is Epoch time. Now I wonder if you can make a mathmatical equation to convert Epoch to regular time. In there a function or framework in swift to so this? I want to turn this, 1469880000
into this H:MM --
.
Asked
Active
Viewed 478 times
0

Paul
- 94
- 9
2 Answers
0
As Alan notes you can use the overloaded method, here's an example.
let date = NSDate(timeIntervalSince1970: 1469880000)
Then to form it you can do something like the following...
let formatString = "yyyy-MM-dd'T'HH:mm:ss.sss'Z'"
func convertTimestampToUTC(inDate:NSDate,formatString:String) -> String{
let formatter = NSDateFormatter()
formatter.dateFormat = formatString
formatter.timeZone = NSTimeZone(abbreviation: "UTC")
let outDate = formatter.stringFromDate(inDate)
return outDate
}
Then use it like so,
let myFormattedDate = convertTimestampToUTC(date, formatString:formatString)
I'll update this shortly with some sample output once I get a moment, hope this helps!

Brandon Brown
- 16
- 1