Is there a TimeGetTime function for iPhone OS

Discussion in 'iOS Programming' started by shweta13, Sep 11, 2008.

  1. shweta13 macrumors member

    Aug 7, 2008
    Hi All,

    I am writing an application where I require the SystemTime i.e. the time elapsed since the system was started. Do we have any API availble in iPhone SDK which can be used in an iPhone application?
    There is an API TimeGetTime() available on Windows we have corresponding API on iPhone OS?

    Thanks alot in advance :)
  2. Ron C macrumors member

    Jul 18, 2008
    The short answer is "It's not obvious where it is if there is one."

    The longer answer is that I did a quick scan of the documents and didn't find it. I found half of it but you'll have to hunt down the boot time of the phone.

    There's CFAbsoluteTimeGetCurrent() (in Dates and Times Programming Guide for Core Foundation), which is the iPhone OS equivalent of the Unix time() library function.

    time() tells you the current time in seconds since Jan 1, 1970 0:00 UTC, but CVAbsoluteTimeGetCurrent() tells you the same quantity but relative to Jan 1 2001 00:00:00 GMT. (I'm pretty sure GMT and UTC the same time zone, one with a world-friendly name and one less so ;))

    To do what you want you'll need to discover how to get the boot time of the iPhone/iPod touch device. I would expect that in the same basic unit as CFAbsoluteTimeGetCurrent(), a CFAbsoluteTime (a typedef for double), and then compute the difference.

    Not much help, but maybe some...

    Ron C

Share This Page