Reputation: 63
I get time in EDT from my server in format yyyy-MM-ddTHH:mm:ss for instance 2014-05-21T09:30:00. I convert these to NSDate and save in sqlite on iphone using code below
NSString *strDate = @"2014-05-21T09:30:00";
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setTimeZone:[NSTimeZone timeZoneWithName:@"EDT"]];
[df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];
NSDate *date = [df dateFromString:strDate];
It works fine until I change the timezone on the device. If I change time on device time gets messed up. Any idea what am I doing wrong here?
How can I save these times so no matter which timezone users is in, they always see eastern time.
Thanks,
D.
Upvotes: 0
Views: 182
Reputation: 10831
NSDate
itself doesn't know about timezone; it's just a simple wrapper around a double value, which represents the number of seconds since some fixed time (I think Jan 1 2001 or something) UTC.
What you need is a NSDateFormatter
, similar to the one you use to parse the date, to transform the NSDate
into an NSString
using the EDT timezone.
Upvotes: 1