Challenge: how many seconds since Birthday - using NSString


#1

I decided to go about this challenge using the apple reference for the NSDate class instead of the Classes suggested in the book, and found it possible to accomplish the task using a single NSDate and NSString instance via the dateWithString method. This would seem like a cleaner, more efficient approach, and since dateWithString accounts for timezone offsets, it should be inherently more precise?

Are there any caveats or limitations to this approach? Would it limit what one could do with this instance later in code?

        NSString *birthDate = @"1975-01-18 03:00:00 -0400";
        NSDate *birth = [NSDate dateWithString:birthDate];
        double secondsSinceBirth = [[NSDate date] timeIntervalSinceDate:birth];
        NSLog(@"It has been %f seconds since my birth", secondsSinceBirth);

-Robert


#2

wow.

I’m impressed! I copied your code and out came the number of seconds you’ve existed. I’m not sure what you did here, fsck66. If you have the time can your repost the code with comments?

[color=#004080]JR[/color]