NSDate is 5 hours off

NSDate defaults to the Universal timezone (aka GMT).

I'm guessing you're somewhere on the East Coast, 5 hours behind UTC.

Try adding this to your date formatter...

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];

[dateFormatter setLocale:[NSLocale currentLocale]];

...and you should see your local time.

If you want to use a specified locale, rather than 'currentLocale', create a NSLocale for the relevant locale.

NSLocale *usLoc = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];

[dateFormatter setLocale:usLoc];

...actually that's US (so possibly not Central).

More specific timezone help can be found here...

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.html

However, if you want to show expiry time, wouldn't you still want it in the user's currentLocale?


If you look at the output you'll see that the log includes the timezone:

2011-09-16 16:14:16.434 iSavemore[1229:7907] now: 2011-09-16 21:14:16 +0000
                                                                      ^^^^^^

The time stamp of your log is local time. I assume you're in a timezone that is 5 hours ahead of UTC.

A NSDate refers to a particular point in time. It's up to you to display this however you want; usually with an NSDateFormatter.

This is the reason why you'll see plenty of recommendations against storing a time, or a date as anything other than an NSDate. If you try and store it as a string you'll run into a lot of trouble later on when trying to handle the display in different timezones.