Skip to content

Instantly share code, notes, and snippets.

@wangchauyan
Created April 7, 2016 07:56
Show Gist options
  • Save wangchauyan/0e47e943ea9c030fd2982c323d49c238 to your computer and use it in GitHub Desktop.
Save wangchauyan/0e47e943ea9c030fd2982c323d49c238 to your computer and use it in GitHub Desktop.
Translate Server GMT +0 to specific local time
// gmt time string from server
NSString *gmtDateString = @"08/12/2013 21:01";
NSDateFormatter *df = [NSDateFormatter new];
[df setDateFormat:@"dd/MM/yyyy HH:mm"];
df.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
NSDate *date = [df dateFromString:gmtDateString];
//Create a date string in the local timezone
df.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:[NSTimeZone localTimeZone].secondsFromGMT];
NSString *localDateString = [df stringFromDate:date];
NSLog(@"date = %@", localDateString);
// Europe/London (GMT+01:00) offset 3600 (Daylight)
// prints out: date = 08/12/2013 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment