• 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
UpTime broken?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

UpTime broken?


  • Subject: UpTime broken?
  • From: David <email@hidden>
  • Date: Tue, 1 Nov 2005 11:24:12 -0600

I'm trying the following code:
double UpTimeInMilliseconds2()
{
	UInt64 result = 0;
	Nanoseconds nanosec = AbsoluteToNanoseconds(UpTime());
	return (double)UnsignedWideToUInt64( nanosec )/1000000.0;

}

- (void)getBootTime
{
struct timeval boottime;
int mib[2];
size_t size;
/*
* Print how long system has been up.
* (Found by looking getting "boottime" from the kernel)
*/
mib[0] = CTL_KERN;
mib[1] = KERN_BOOTTIME;
size = sizeof(boottime);
if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 && boottime.tv_sec != 0) {
bootDate = [[NSCalendarDate dateWithTimeIntervalSince1970:boottime.tv_sec] retain];
}
}
.
.
.
double uptime3 = UpTimeInMilliseconds2()/1000.0;
NSCalendarDate *currentDate = [bootDate addTimeInterval:uptime3];



The currentDate is correct if the computer has an uptime of less than 1 day. After that it is off by aprox. 2 hours and may get worse the longer the computer is on.



The following newDate will produce the correct date: NSCalendarDate *aDate = [NSCalendarDate calendarDate]; NSTimeInterval i2 = [aDate timeIntervalSince1970]; NSTimeInterval i3 = [bootDate timeIntervalSince1970]; NSTimeInterval i4 = i2 - i3; NSCalendarDate *newDate = [bootDate addTimeInterval:i4];

I am trying to use the UpTime to get millisecond precision for time stamping and adding that value to the boot time to get the actual date/time of the time stamp.

So what is wrong with the UpTimeInMilliseconds2 routine or does anyone have documentation on what exactly UpTime returns? I thought it was based off of Jan 1, 1970.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: UpTime broken?
      • From: Andrew Farmer <email@hidden>
  • Prev by Date: Re: _NSKeyValueObservationInfoCreateByRemoving crashing
  • Next by Date: Re: _NSKeyValueObservationInfoCreateByRemoving crashing
  • Previous by thread: Scroll wheels - typical deltas?
  • Next by thread: Re: UpTime broken?
  • Index(es):
    • Date
    • Thread