我正在进行 Objective-C (iOS) 开发。我想知道如何将默认时区 GMT +0 更改为 GMT +8。 GMT +8 为新加坡。
这是我的代码:
- (IBAction)dateChanged {
NSDate *choice = [datePick date];
NSString *words = [NSString alloc initWithFormat:@"%@", choice];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You have selected:" message:words delegate:nil cancelButoonTitle:@"OK" otherBUttonTitles:nil, nil];
[alert show];
[alert release];
[words release];
}
谢谢。
最佳答案
您可以使用,
NSCalendar *calendar = [NSCalendar currentCalendar];
[calendar setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
或者,
+ (id)timeZoneForSecondsFromGMT:(NSInteger)seconds
这将是你的情况,
[calendar setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:8*60*60]];
关于iphone - 更改时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7089810/