title: Uptime iOS Objective-C - millisecond precision
body: <p>I'm trying to get uptime for iOS. I was using mach_absolute_time - but I found that it paused during sleep. </p>
  
  <p>I found this snippet:</p>
  
  <pre><code>- (time_t)uptime
  {
      struct timeval boottime;
      int mib[2] = {CTL_KERN, KERN_BOOTTIME};
      size_t size = sizeof(boottime);
      time_t now;
      time_t uptime = -1;
  
      (void)time(&amp;now);
  
      if (sysctl(mib, 2, &amp;boottime, &amp;size, NULL, 0) != -1 &amp;&amp; boottime.tv_sec != 0)
      {
          uptime = now - boottime.tv_sec;
      }
      return uptime;
  }
  </code></pre>
  
  <p>It does the trick. BUT, it's returning whole seconds. Any way to get milliseconds out of this?</p>