NSDate's GMT offset changing with month change.

  • I create two NSDates, but the only difference is the month, but the
    hour and GMT offset changes, why?

    The code:

    int main (int argc, const char * argv[])
    {
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    NSDate *dateOne = [NSDate dateWithString:@"2006-9-02 7:30:12 -0700"];
    NSDate *dateTwo = [NSDate dateWithString:@"2006-1-02 7:30:12 -0700"];

    NSLog(@"dateOne: %@", [dateOne description]);
    NSLog(@"dateTwo: %@", [dateTwo description]);

        [pool release];
        return 0;
    }

    The output:

    2006-09-30 14:54:39.012 NSDateTest[6958] dateOne: 2006-09-02 07:30:12 -0700
    2006-09-30 14:54:39.013 NSDateTest[6958] dateTwo: 2006-01-02 06:30:12 -0800
  • On Sep 30, 2006, at 5:07 PM, Jordan Evans wrote:

    > I create two NSDates, but the only difference is the month, but the
    > hour and GMT offset changes, why?
    >
    >
    > The code:
    >
    > int main (int argc, const char * argv[])
    > {
    > NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    >
    > NSDate *dateOne = [NSDate dateWithString:@"2006-9-02 7:30:12 -0700"];
    > NSDate *dateTwo = [NSDate dateWithString:@"2006-1-02 7:30:12 -0700"];
    >
    > NSLog(@"dateOne: %@", [dateOne description]);
    > NSLog(@"dateTwo: %@", [dateTwo description]);
    >
    > [pool release];
    > return 0;
    > }
    >
    > The output:
    >
    > 2006-09-30 14:54:39.012 NSDateTest[6958] dateOne: 2006-09-02
    > 07:30:12 -0700
    > 2006-09-30 14:54:39.013 NSDateTest[6958] dateTwo: 2006-01-02
    > 06:30:12 -0800

    Looks like something to do with Daylight Saving Time.  Do you honor
    DST in your time zone?  As an experiment, try using a time zone that
    doesn't honor DST (e.g. Hawaii); my guess is that the times you
    construct will no longer be auto-adjusted.

    ___________________________________________________________
    Ricky A. Sharp        mailto:<rsharp...>
    Instant Interactive(tm)  http://www.instantinteractive.com
previous month october 2006 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 31          
Go to today