Convert milliseconds to NSDate

Solution 1:

These functions (dateWithTimeIntervalSince1970, dateWithTimeIntervalSinceReferenceDate, dateWithTimeIntervalSinceNow) accept parameter in seconds.

NSDate *date = [NSDate dateWithTimeIntervalSince1970:(ms / 1000.0)];

You should pass 1273636800.000

NSDate *date = [NSDate dateWithTimeIntervalSince1970:(1273636800 / 1000.0)];

Solution 2:

Divide by 1000 to get millis in seconds, that's what you want.

Solution 3:

A simple one-line Swift 2 function:

func dateFromMilliseconds(ms: NSNumber) -> NSDate {
    return NSDate(timeIntervalSince1970:Double(ms) / 1000.0)
}