Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tatsuro-ueda/3323933 to your computer and use it in GitHub Desktop.
Save tatsuro-ueda/3323933 to your computer and use it in GitHub Desktop.
ローカル時間の変換をするには

##Convert GMT to IST in iOS

The code below convert GMT to IST.

NSString *inDateStr = @"2000/01/02 03:04:05";
NSString *s = @"yyyy/MM/dd HH:mm:ss";

// about input date(GMT)
NSDateFormatter *inDateFormatter = [[NSDateFormatter alloc] init];
inDateFormatter.dateFormat = s;
inDateFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
NSDate *inDate = [inDateFormatter dateFromString:inDateStr];

// about output date(IST)
NSDateFormatter *outDateFormatter = [[NSDateFormatter alloc] init];
outDateFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"IST"];
outDateFormatter.dateFormat = s;
NSString *outDateStr = [outDateFormatter stringFromDate:inDate];

// final output
NSLog(@"[in]%@ -> [out]%@", inDateStr, outDateStr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment