我想將我的本地日期([NSDate日期])轉換爲GMT以創建一個JSON字符串(/ Date(1324435876019-0000)/)。NSDate到GMTDate到JSON格式
當我將我的時鐘設置爲EST時區時,我的代碼正常工作,當我將時區更改爲PST時,我的代碼仍然用作EST。你能告訴我下面的代碼是什麼問題?
NSDate *localDate = [NSDate date];
NSTimeInterval timeZoneOffset = [[NSTimeZone systemTimeZone] secondsFromGMT]; // You could also use the systemTimeZone method
NSTimeInterval gmtTimeInterval = [localDate timeIntervalSinceReferenceDate] - timeZoneOffset;
NSDate *gmtDate = [NSDate dateWithTimeIntervalSinceReferenceDate:gmtTimeInterval];
NSString *time = [NSString stringWithFormat:@"/Date(%@-0000)/", [NSNumber numberWithLongLong:[gmtDate timeIntervalSince1970] * 1000]];
當前時間是2011-12-20 05:15:00 +0000但是,如果我NSLog gmtDate我出去把作爲1)ESt時區:2011-12-21 03:15: 00 +0000 2)PSTtime區域:2011-12-21 06:15:00 +0000。這是錯誤的。我想我沒有得到正確的格林威治時間日期。你怎麼看 ? – AAV 2011-12-20 22:18:27