Posts

Post not yet marked as solved
1 Replies
345 Views
I'm storing dates in an NSDictionary and even though it creates a very weird value when stored, it returns the correct time in my time zone. However, if I change my time zone and read the value, I don't get values offset by the hour - I get weird values: Original time in my date object in NY: 9:10:20 am Value stored in Dict: Dict {Time = "0001-01-01 14:06:22 +0000";} Value returned from objectForKey: New York 9:10:20 am Chicago 8:15:46 am Denver 7:06:26 am California 6:13:24 am I'll post my code here but I'm at a loss to figure out how to fix this. NSLog(@"Original Date %@",date); NSDictionary *myDict = [[NSDictionary alloc] initWithObjectsAndKeys:date,@"Time", nil]; NSLog(@"MyDict %@", myDict); NSDate *tempDate = [myDict objectForKey:@"Time"]; NSLog(@"tempDate %@",tempDate); Even if I format it, it is wrong: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4]; [dateFormatter setDateStyle:NSDateFormatterNoStyle]; [dateFormatter setTimeStyle:NSDateFormatterNoStyle]; [dateFormatter setDateFormat:@"h:mm:ss a"]; return [dateFormatter stringFromDate:date]; The good news is that it seems to convert to/from NSDictionary in whatever time zone it was created in, but this is a big issue for anyone that travels with our app. Thoughts about what causes this and what can fix it? If the app wasn't already released and in use, I'd simply change my storage format. I need to have this work with existing data.
Posted
by Giebler.
Last updated
.