user2163780
user2163780

Reputation: 173

GMT offset for date in Objective-C

I need GMT offset for date only. I am using this method

double numberOfHours = (double)[timeZone secondsFromGMTForDate:date]/ 3600.0;

Actually in Berlin, Germany DST would be ON at 31st March, 2013 and time will change at 2:00 am. The problem is I want GMT offset using date only. If date = 31-3-2013 00:00:00 then it returns +1. it returns +2 after 31-3-2013 02:00:00. Is there any method/way I can get timezone offset without using time components?

Upvotes: 1

Views: 1379

Answers (3)

Sadia
Sadia

Reputation: 462

if you want to avoid using time components. you can use these methods

nextDaylightSavingTimeTransition and daylightSavingTimeOffsetForDate:NSDate

of NSTimeZone class.

Upvotes: 1

Adis
Adis

Reputation: 4552

You can probably use an NSDateFormatter with a custom date format such as @"zzz", which will return the timezone offset for a given NSDate.

Upvotes: 1

borrrden
borrrden

Reputation: 33421

How about just changing the time on your date to the middle of the day and testing that instead?

But no, without any time components at all the date will default to midnight and you will get the (correct for that time) result of +1.

Upvotes: 1

Related Questions