anasabufarraj anasabufarraj - 1 year ago 121
Objective-C Question

How to set the timezone on NSDateComponents

I'm trying to encapsulate a time using a

..but it give me 1979-05-10 08:30:00 +0000....what value should set for
to give me the Houres in my local time (GMT+2) which should be 1979-05-10 10:30:00 +0000

NSDateComponents *comp = [[NSDateComponents alloc] init];
[comp setYear:1979];
[comp setMonth:5];
[comp setDay:10];
[comp setHour:10];
[comp setMinute:30];
[comp setTimeZone:];

Answer Source

You can use +(NSTimeZone) timeZoneForSecondsFromGMT:. To convert hours to seconds, multiply by 3600.


For GMT+2

[NSTimeZone timeZoneForSecondsFromGMT:3600*2]

For GMT-2

[NSTimeZone timeZoneForSecondsFromGMT:-3600*2]

To get the timezone local to your device:

[NSTimeZone localTimeZone]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download