2017-01-03 31 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

您可以根據需要更改源和目​​標時區。天氣系統時區或其他時區。 –

相關問題