gpt4 book ai didi

iphone - 更改时区

转载 作者:行者123 更新时间:2023-11-29 05:00:28 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com