转换时间不正确

时间:2013-11-21 10:29:40

标签: ios objective-c timezone nsdate

我需要转换从服务器到用户的时间。 我用这段代码。

- (NSString *)convertServerTime:(NSString *)serverTime
{
    NSDateFormatter *serverFormatter = [[NSDateFormatter alloc] init];
    [serverFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
    [serverFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    NSDate *theDate = [serverFormatter dateFromString:serverTime];

    NSDateFormatter *userFormatter = [[NSDateFormatter alloc] init];
    [userFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    [userFormatter setTimeZone:[NSTimeZone systemTimeZone]];

    NSString *dateConverted = [userFormatter stringFromDate:theDate];
    return dateConverted;
}

系统时区:(欧洲/伦敦(GMT)偏移0)

serverTime:2014-08-11 00:00

dateConverted:2014-08-11 01:00

但我需要和serverTime一样。相反,我收到+1小时。请帮帮我。

0 个答案:

没有答案