开发者

Dateformatter applying time zone to datetime

I am having a problem with my datetime field getting changed by th开发者_开发百科e time zone.

The incoming datetime is -- 2010-12-28 19:10:00

only when I use get date from string it comes out as -- 2010-12-29 00:10:00 +0000

I am doing

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];

[dateFormatter setDateStyle:NSDateFormatterFullStyle];
[[dateFormatter locale] localeIdentifier];
[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
[dateFormatter setTimeStyle:NSDateFormatterLongStyle];

[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

p.date = [dateFormatter dateFromString:[values objectAtIndex:6]];

It's like it it applies GMT and adds 5 hours to my date time. How can I stop this from happening.

thanks Cheryl


Assuming your local time is GMT-5, this is perfectly fine. 2010-12-29 00:10:00 +0000 and 2010-12-28 19:10:00 -0500 both identify exactly the same point in time. And that is all an NSDate represents: a single point in time. The time zone in which you display it is determined when you create another date formatter to convert the date back to a string for display.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜