Inconsistencies with NSDate timeIntervalSinceReferenceDate

  • I seem to be getting some major inconsistencies when using NSDate
    timeIntervalSinceReferenceDate....
    Let me explain...

    I have the following code:

    NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
    NSLog(@"%@", [NSDate dateWithTimeIntervalSinceReferenceDate: now]);
    NSLog(@"%@", [NSString stringWithFormat:@"%d", now]);

    Now the first NSLog returns the correct date, however the second NSLog
    returns what seems to be wild numbers.
    For example here is the output from a few runs:

    2007-11-21 17:26:37 -0700
    2060718229

    2007-11-21 17:26:38 -0700
    2108793912

    2007-11-21 17:26:43 -0700
    -2028003597

    So as you can see the first 2 runs it looks somewhat ok (Seems like a
    huge number difference for a change of 1 second)
    Then the third run, I get a WAY different number, both in it being a
    negative and a big difference between even just the numbers.

    According to the NSDate class reference it says a negative is used to
    specify a date and time before the reference date of 1 January 2001, GMT.

    Is this normal output?
    Do I just not understand timeIntervalSinceReferenceDate?
    Am I doing something wrong?

    Any help would be appreciated.

    Thanks.
  • On Nov 21, 2007 7:01 PM, Dallas Brown <dbrown...> wrote:
    > I seem to be getting some major inconsistencies when using NSDate
    > timeIntervalSinceReferenceDate....
    > Let me explain...
    >
    > I have the following code:
    >
    > NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
    > NSLog(@"%@", [NSDate dateWithTimeIntervalSinceReferenceDate: now]);
    > NSLog(@"%@", [NSString stringWithFormat:@"%d", now]);

    NSTimeinterval is a double, not an integer. Try @"%f".
  • > NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
    > NSLog(@"%@", [NSDate dateWithTimeIntervalSinceReferenceDate: now]);
    > NSLog(@"%@", [NSString stringWithFormat:@"%d", now]);

    http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Miscell
    a

    neous/Foundation_DataTypes/Reference/reference.html

    typedef double NSTimeInterval;
            ------
  • Oh man....
    I can't believe I missed that...

    Thanks, and sorry.


    stephen joseph butler wrote:
    > On Nov 21, 2007 7:01 PM, Dallas Brown <dbrown...> wrote:
    >
    >> I seem to be getting some major inconsistencies when using NSDate
    >> timeIntervalSinceReferenceDate....
    >> Let me explain...
    >>
    >> I have the following code:
    >>
    >> NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
    >> NSLog(@"%@", [NSDate dateWithTimeIntervalSinceReferenceDate: now]);
    >> NSLog(@"%@", [NSString stringWithFormat:@"%d", now]);
    >>
    >
    > NSTimeinterval is a double, not an integer. Try @"%f".
    >
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today