Alex Rivera | Logout

Is there an objective-c/iPhone version of currentTimeMillis() from Java?

Asked 2010-09-09T23:14:17.823
15

I need to time some events in the app I'm working on. In Java i used to be able to call currentTimeMillis() but there doesnt seem to be a version in Objective-c. Is there a way to check there current time without creating a NSDate and then parsing this object everytime i need this information?

Thanks -Code

Edit
Report

1 Answer

7

To get very cheap very precise time, you can use gettimeofday(), which is a C Function of the BSD kernel. Please read the man page for full details, but here's an simple example:

struct timeval t;
gettimeofday(&t, NULL);

long msec = t.tv_sec * 1000 + t.tv_usec / 1000;
answered 2010-09-09T23:24:53.640

Your Answer