獲取時間相差8小時的處理辦法:
現(xiàn)將需要轉(zhuǎn)換的時間轉(zhuǎn)換為nsdata:timeUtc
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"YYYY/MM/dd hh:mm:ss"];
NSDate *te? ? = [self getNowDateFromatAnDate:timeUtc];
NSString *str = [NSString stringWithFormat:@"%@",te];
dateString? ? = [str substringToIndex:19];
- (NSDate *)getNowDateFromatAnDate:(NSDate *)anyDate
{
//設置源日期時區(qū)
NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];//或GMT
//設置轉(zhuǎn)換后的目標日期時區(qū)
NSTimeZone* destinationTimeZone = [NSTimeZone localTimeZone];
//得到源日期與世界標準時間的偏移量
NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:anyDate];
//目標日期與本地時區(qū)的偏移量
NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:anyDate];
//得到時間偏移量的差值
NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;
//轉(zhuǎn)為現(xiàn)在時間
NSDate* destinationDateNow = [[NSDate alloc] initWithTimeInterval:interval sinceDate:anyDate];
return destinationDateNow;
}