0

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

vp2698
  • 1,783
  • 26
  • 28
  • [`NSDate`s are independent of time zones](https://stackoverflow.com/questions/7485493/get-nsdate-from-nsdate-adjusted-with-timezone/11887312#11887312). – albertamg Aug 29 '17 at 11:55
  • @albertamg I know but basically i want to add/minus time from current Time using TimeZone offset – vp2698 Aug 29 '17 at 11:58
  • Hope this helps: https://stackoverflow.com/questions/27053135/how-to-get-a-users-time-zone – Amit Aug 29 '17 at 12:03
  • Get timeinterval, add/minus offset to interval, create new NSDate from new timeinterval. – Cy-4AH Aug 29 '17 at 12:11
  • I don't think that both question is same and i am not getting how you moderate question – vp2698 Aug 29 '17 at 13:02

1 Answers1

0

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

user6788419
  • 7,196
  • 1
  • 16
  • 28