Get current date in milliseconds Get current date in milliseconds ios ios

Get current date in milliseconds


There are several ways of doing this, although my personal favorite is:

CFAbsoluteTime timeInSeconds = CFAbsoluteTimeGetCurrent();

You can read more about this method here. You can also create a NSDate object and get time by calling timeIntervalSince1970 which returns the seconds since 1/1/1970:

NSTimeInterval timeInSeconds = [[NSDate date] timeIntervalSince1970];

And in Swift:

let timeInSeconds: TimeInterval = Date().timeIntervalSince1970


Casting the NSTimeInterval directly to a long overflowed for me, so instead I had to cast to a long long.

long long milliseconds = (long long)([[NSDate date] timeIntervalSince1970] * 1000.0);

The result is a 13 digit timestamp as in Unix.


NSTimeInterval milisecondedDate = ([[NSDate date] timeIntervalSince1970] * 1000);