iphone - 更改时区

标签 iphone objective-c ios timezone gmt

我正在进行 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/

相关文章:

iphone - iPhone 应用程序的无线部署

ios - 网页加载后事件指示器不隐藏

iOS:AVPlayer 显示黑屏并且无法播放某些 mp4 视频

jquery - jPlayer 2.0 iPhone/手机问题

ios - 将场景锁定到 Sprite 节点 swift xcode

objective-c - 你如何在 Objective-C 中检索可用物理 RAM 的数量?

ios - youtube 收到错误呈现模板 : Error Domain=NSCocoaErrorDomain Code=258

iphone - 自定义类上的 NSData?

ios - 如何解析JSON多数组

ios - 完全隐藏搜索栏