0

In javascript we can get timezone offset with

var current_date = new Date();
current_date.getTimezoneOffset();

Result => -330

I want to get that in iOS (Objective-C)

can someone help please ?

  • possible duplicate of [Time Zone offset number in Objective-c?](http://stackoverflow.com/questions/2611369/time-zone-offset-number-in-objective-c) – bufh Aug 04 '15 at 12:33
  • How would you want the current timezone offset on the device in HOURS or in SECONDS? –  Aug 04 '15 at 12:36

1 Answers1

4

There is a very nice NSTimeZone object which will give you the timezone offset from GMT in seconds: Below code gives you timezone offset in HOURS

NSDate *sourceDate = [NSDate date];
NSTimeZone* destinationTimeZone = [NSTimeZone localTimeZone];
float timeZoneOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate] / 3600.0;
NSLog(@"sourceDate=%@ timeZoneOffset=%f", sourceDate, timeZoneOffset);