Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do NSDate's in CoreData encapsulate time zone?

I keep dates and times in my CoreData store and need to accurately present to users the time as originally entered. The problem is that if they entered 4:00 on the East Coast, then later look at the recorded time on the West Coast, it appears as 1:00, since the iPhone translates universal times to local times. I need it to show 4:00 -- probably 4:00 (+3h00).

Before I go and restructure my Core Data model, I want to be sure there's no way to derive the NSTimeZone that was active at creation-time from a stored NSDate object. Is there? If not, any recommendation how best to capture NSTimeZone at creation time myself? An NSNumber representing the creation-time NSTimeZone time difference from GMT?

Thanks.

like image 764
ed94133 Avatar asked Jan 18 '11 08:01

ed94133


1 Answers

As you've discovered, NSDate represents a universal point in time and does not include specific time zone information.

I'd suggest instead of storing the offset, store the NSTimeZone's name property. Then you can use +[NSTimeZone timeZoneWithName:] to get the time zone and thence convert it to local time. This gives you maximum flexibility in how you display the information to the user.

like image 135
grahamparks Avatar answered Sep 28 '22 11:09

grahamparks