NSDate *dateNow = [NSDate date];
NSLog(@"NSDate : %@", dateNow);
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setLocale:[NSLocale currentLocale]];
[dateFormatter setTimeStyle:NSDateFormatterLongStyle];
NSString *dateString = [dateFormatter stringFromDate:dateNow];
NSLog(@"NSDateFormatter String: %@", dateString);
NSDate *dateObject = [dateFormatter dateFromString:dateString];
NSLog(@"NSDateFormatter Object: %@", dateObject);
First off ignore the 1970-01-01 I am only interested in the time for now.
My question is when I get the time from NSDate it does not include any time zone information. This is what I expected so the time returned from NSDate is 01:21:57 PM. To correct this I am using NSDateFormatter and setting its locale, it correctly interprets that I am in London, British Summer Time (GMT+01). Finally I want to get the new corrected date back as an NSDate so I use dateFromString on the previously correct dateString.
Can anyone tell me why the resultant date reverts back to being uncorrected (i.e. 01:21:57 PM) is there anyway that I can do this conversion and still maintain the specified locale / timeZone?
>> WALL_CLOCK: 02:21:57 PM
>> NSDate : 2011-04-08 01:21:57 PM +0000
>> NSDateFormatter String: 02:21:57 PM GMT+01:00
>> NSDateFormatter Object: 1970-01-01 01:21:57 PM +0000