Re: Milliseconds Function?
Re: Milliseconds Function?
- Subject: Re: Milliseconds Function?
- From: James Montgomerie <email@hidden>
- Date: Fri, 25 Jan 2002 17:51:55 -0800
On Friday, January 25, 2002, at 05:12 pm, Brian Moore wrote:
>
I've looked around and searched the cocoa docs for some method or
>
function which would allow me to get the current milliseconds
>
(000-999). I've deduced a messy and expensive way: [[[NSCalendarDate
>
date] descriptionWithCalendarFormat:@"%F"] intValue], which works...but
>
it uses way too many CPU cycles to be realistically usable. I apologize
>
in advance if this is unbelievably obvious, but I couldn't find a
>
single way. Can anyone help me?
>
You could use gettimeofday() - it's not Cocoa, it's BSD, but it's quite
straightforward to use. It returns microseconds and seconds. For
example:
struct timeval tv;
long milliseconds;
if(gettimeofday(&tv, NULL) == 0)
milliseconds = tv.tv_usec/1000;
else
printf("Never mind. Time's only an abstract concept anyway.");
Seem man gettimeofday for more usage instructions.
Jamie.