Created
April 7, 2016 07:56
-
-
Save wangchauyan/0e47e943ea9c030fd2982c323d49c238 to your computer and use it in GitHub Desktop.
Translate Server GMT +0 to specific local time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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