Time offset from NSDate with TimeZone
suggest changeHere this will calculate the UTC time offset from the current date in the desired timezone. secondsFromGMTForDate: on UTC is 0, so the result is the current zone’s offset from UTC.
+(NSTimeInterval)getUTCOffSetIntervalWithCurrentTimeZone:(NSTimeZone *)current forDate:(NSDate *)date {
NSTimeZone *utcTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
NSInteger currentGMTOffset = [current secondsFromGMTForDate:date];
NSInteger gmtOffset = [utcTimeZone secondsFromGMTForDate:date];
NSTimeInterval gmtInterval = currentGMTOffset - gmtOffset;
return gmtInterval;
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents