2017-01-03 33 views
2

即使时区更改,如何保持同一日期。例如:我在印度,IST时区。我已在上午10点设置提醒。我搬到美国(有5个时区),我在PDT。它应该提醒我在早上10点PDT,而不是晚上8点30分PDT。请帮助!即使更改时区,如何保持同一日期

+0

所以如果IST领先于PDT 12.30h,现在是加尔各答的10点。 PDT中什么时候会发生10点? – Andy

回答

-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]; 
+0

仍不能得到它! –

+0

此代码不正确,它根据设备的系统时间计算墨尔本当地时间。 – Andy

+0

您可以根据需要更改源和目​​标时区。天气系统时区或其他时区。 –

相关问题