서버에서 시간을 얻고 있습니다 2016/07/19--12:20:00
이제는이 시간을 국가에 맞게 변경해야합니다. 예를 들어 내가 오클랜드에있는 경우 시간은 같아야합니다 2016/07/19--18:50:00
스택 오버플로에서 너무 많은 솔루션을 발견했지만 해결할 수 없습니다. 나에게내 서버 시간을 다른 국가 시간으로 변환하는 방법?
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"YYYY/MM/dd--HH:mm:ss"];
NSDate* sourceDate = [dateFormatter dateFromString:model.tripEndTime];
NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
NSTimeZone* destinationTimeZone = [NSTimeZone localTimeZone];
NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:sourceDate];
NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate];
NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;
NSDate* destinationDate = [[NSDate alloc] initWithTimeInterval:interval sinceDate:sourceDate];
NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setTimeZone:[NSTimeZone systemTimeZone]];
[dateFormat setDateFormat:@"YYYY/MM/dd--HH:mm:ss"];
NSString* localTime = [dateFormat stringFromDate:destinationDate];
NSLog(@"localTime:%@", localTime);
도와주세요이 코드
ur 시도한 코드를 표시 할 수 있습니다 –
GMT에서 서버 시간입니까? – Avi