Created
September 3, 2013 08:44
-
-
Save neiraza/6421259 to your computer and use it in GitHub Desktop.
UTCな時間(文字列)をNSDateなローカル時間に変換する
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
NSString *tmp = @"2013-09-03T08:29:16.575Z"; | |
NSDate *date = [[tmp dateFromStringWithFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"] toLocalTime]; |
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
- (NSDate *)toLocalTime | |
{ | |
NSTimeZone *tz = [NSTimeZone defaultTimeZone]; | |
NSInteger seconds = [tz secondsFromGMTForDate:self]; | |
return [NSDate dateWithTimeInterval:seconds sinceDate:self]; | |
} | |
- (NSDate *)toGlobalTime | |
{ | |
NSTimeZone *tz = [NSTimeZone defaultTimeZone]; | |
NSInteger seconds = -[tz secondsFromGMTForDate:self]; | |
return [NSDate dateWithTimeInterval:seconds sinceDate:self]; | |
} |
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
- (NSDate *)dateFromStringWithFormat:(NSString *)format | |
{ | |
return [self dateFromStringWithTimeZone:[[[NSTimeZone alloc] initWithName:@"UTC"] autorelease] format:format]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment