Get current date in milliseconds

siva picture siva · May 27, 2011 · Viewed 132.1k times · Source

Can any one give me an idea how to get the current date in milliseconds?

Answer

Pawel picture Pawel · May 27, 2011

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