Here’s a NSDate category to convert UTC (or GMT) to local time and back.

#import "NSDate+Utils.h"

@implementation NSDate (Utils)

-(NSDate *) toLocalTime
{
    NSTimeZone *tz = [NSTimeZone localTimeZone];
    NSInteger seconds = [tz secondsFromGMTForDate: self];
    return [NSDate dateWithTimeInterval: seconds sinceDate: self];
}

-(NSDate *) toGlobalTime
{
    NSTimeZone *tz = [NSTimeZone localTimeZone];
    NSInteger seconds = -[tz secondsFromGMTForDate: self];
    return [NSDate dateWithTimeInterval: seconds sinceDate: self];
}

@end

Links that help
http://stackoverflow.com/questions/1268509/convert-utc-nsdate-to-local-timezone-objective-c
http://stackoverflow.com/questions/5985468/iphone-differences-among-time-zone-convenience-methods

Advertisements