DateUtils.m
changeset 2 3d3dcc3116d5
child 4 64823cdde6a5
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/DateUtils.m	Wed Apr 02 14:45:33 2008 -0700
     1.3 @@ -0,0 +1,28 @@
     1.4 +//
     1.5 +//  DateUtils.m
     1.6 +//  Cloudy
     1.7 +//
     1.8 +//  Created by Jens Alfke on 3/25/08.
     1.9 +//  Copyright 2008 __MyCompanyName__. All rights reserved.
    1.10 +//
    1.11 +
    1.12 +#import "DateUtils.h"
    1.13 +
    1.14 +#include <assert.h>
    1.15 +#include <CoreServices/CoreServices.h>
    1.16 +#include <mach/mach.h>
    1.17 +#include <mach/mach_time.h>
    1.18 +#include <unistd.h>
    1.19 +
    1.20 +
    1.21 +NSTimeInterval TimeIntervalSinceBoot(void)
    1.22 +{
    1.23 +    // From http://developer.apple.com/qa/qa2004/qa1398.html
    1.24 +    uint64_t abstime = mach_absolute_time();
    1.25 +    // Have to do some pointer fun because AbsoluteToNanoseconds
    1.26 +    // works in terms of UnsignedWide, which is a structure rather
    1.27 +    // than a proper 64-bit integer.
    1.28 +    Nanoseconds elapsedNano = AbsoluteToNanoseconds( *(AbsoluteTime *) &abstime );
    1.29 +    return *(uint64_t*)&elapsedNano / 1.0e9;
    1.30 +}
    1.31 +