• 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: Douglas Davidson <email@hidden>
  • Date: Fri, 25 Jan 2002 18:14:11 -0800

On Friday, January 25, 2002, at 05:51 PM, James Montgomerie 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:

For Cocoaish alternatives look in CFDate.h (e.g. CFAbsoluteTimeGetCurrent()) and NSDate.h (e.g. [NSDate timeIntervalSinceReferenceDate]), but the right choice really depends on what you want this for.

Douglas Davidson


References: 
 >Re: Milliseconds Function? (From: James Montgomerie <email@hidden>)

  • Prev by Date: Re: How viable is Cocoa development?
  • Next by Date: Re: How viable is Cocoa development?
  • Previous by thread: Re: Milliseconds Function?
  • Next by thread: Re: Milliseconds Function?
  • Index(es):
    • Date
    • Thread