即使更改时区,如何保持相同的日期。例如:我在印度,IST时区。我在IST上午10点设置提醒。我移居美国(有5个时区),我在PDT。它应该在太平洋夏令时间上午10点而不是太平洋时间晚上8:30提醒我。请帮忙!
答案 0 :(得分:-1)
您可以使用此代码。可能对你有帮助。
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];