I am not sure what I am missing here but it has been driving me nuts for the past few hours trying to figure this out.
I am trying to save the date/time from a UIDatePicker into an SQLite database using UTC format.
So I use the UIDatePicker and shows the time for: 2009-11-15T00:30 as 7:30pm. (-0500 timezone what it is defaulting to.)
However, my issue is later. I access this data and use dateFromString and the time is off by an hour. For whatever reason it no longer uses the -0500 time zone it used with the UIDatePicker to convert the UTC time but now uses -0600 timezone. I have No idea what has changed to make it -0600 vs the -0500.
Code:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation: @"UTC"]];
NSDate *sqlDateFormatted = [[NSDate alloc] init];
sqlDateFormatted = [dateFormatter dateFromString:savedSqlDate];
NSLog(@"savedSqlDate: %@", savedSqlDate);
NSLog(@"sqlDateFormatted: %@", sqlDateFormatted);
[dateFormatter release];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MM/dd/yyyy hh:mma"];
NSString *dateString = [dateFormat stringFromDate:sqlDateFormatted];
NSLog(@"dateString: %@",dateString);
cell.gameDate.text = dateString;
[dateFormat release];
NSlog info:
savedSqlDate: 2010-01-09T00:30
sqlDateFormatted: 2010-01-08 18:30:00 -0600
dateString: 01/08/2010 06:30PM