How to add/minus TimeZone offset in NSDate

476 views Asked by At

I am getting current GMT time using

NSDate * now = [NSDate date];

But i want to add/minus timezone offset in date for different city. i am getting offset from server.

Example : I am getting +2:30 GMT from server so i have to add +2:30 GMT in my current GMT time

or if i am getting -6 GMT so how can i minus it from current time. My question is basically how to add or minus Hours like +2:30

1

There are 1 answers

0
user6788419 On

You can set GMT value in date formatter

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
NSTimeZone *tz = [NSTimeZone timeZoneForSecondsFromGMT:9000]; // GMT+2.30
[formatter setTimeZone:tz];

Note : 1 hour = 3600 seconds, So in the above example 2.30 hr = 9000 seconds

Hope this will help you