How to keep same date even if time zone is changed

52 views Asked by At

How to keep same date even if time zone is changed. for example: I am in India, IST timezone. I have setup reminder at 10am IST. I move to USA (which has 5 timezones), I m in PDT. It should remind me at 10am PDT and not 8:30pm PDT.Please help!

1

There are 1 answers

3
Avineet Gupta On

You can Use this Code . might be it helpful for you.

NSDate sourceDate = Yourdate;

NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithName:@"Australia/Melbourne"];

NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone]; // your device time . you can also change any time zone like above.

NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:sourceDate];
NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate];

NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;

NSDate* destinationDate = [[NSDate alloc] initWithTimeInterval:interval sinceDate:sourceDate];