• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Milliseconds Function?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Milliseconds Function?


  • Subject: Re: Milliseconds Function?
  • From: jgo <email@hidden>
  • Date: Mon, 28 Jan 2002 14:33:03 -0800

> James Montgomerie wrote:
>> On Friday, 2002 January 25 at 17:12, 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.

Check the archives. We've been down this road, before.
The up-shot that I recall was that the timing was nominally
available in microseconds, but those are just the units in
which it was reported. It was far less precise than that.
How much less -- whether it was good to the millisecond or
centisecond, I don't recall.

John G. Otto, Eagle Scout, Knight, Cybernetic Praxeologist
Existence, Consciousness, Identity, Life, Liberty, Property, Privacy, Justice
<http://gosc.nisus.com/~giovanni>


  • Follow-Ups:
    • Re: Milliseconds Function?
      • From: "Erik M. Buck" <email@hidden>
References: 
 >Milliseconds Function? (From: Brian Moore <email@hidden>)
 >Re: Milliseconds Function? (From: James Montgomerie <email@hidden>)

  • Prev by Date: Re: Database Access
  • Next by Date: NSTableView Data Source problems
  • Previous by thread: Re: Milliseconds Function?
  • Next by thread: Re: Milliseconds Function?
  • Index(es):
    • Date
    • Thread