我想将我的本地日期 ([NSDate date]) 转换为 GMT 以创建 JSON 字符串 (/Date(1324435876019-0000)/)。
当我将时钟设置为 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]];