首页 > 代码库 > NSDate NSTimerZone 时区转换

NSDate NSTimerZone 时区转换

timeZoneAbbreviation = @“America/New_York”;

 

 

#pragma mark - 转换时区

- (NSDate *) convertDate:(NSDate *) date toTimeZone:(NSString *) timeZoneAbbreviation {

    if (!date) {

        return nil;

    }

    NSTimeZone *locationZone  = [NSTimeZonesystemTimeZone];

    NSTimeZone *zoneUTC     =   [NSTimeZone timeZoneWithName:timeZoneAbbreviation];

    NSTimeInterval s        = [zoneUTC secondsFromGMTForDate:date];

    NSTimeInterval p        = [locationZone secondsFromGMTForDate:date];

    NSTimeInterval i = s-p;

    NSDate *d = [NSDatedateWithTimeInterval:i sinceDate:date];

    return d;

}