????????????NSDate *date=[NSDate date];//獲取時(shí)間date
? ? ? ? ? ? NSTimeZone* localTimeZone = [NSTimeZone localTimeZone];//獲取手機(jī)當(dāng)前時(shí)區(qū)
? ? ? ? ? ? NSIntegeroffset = [localTimeZonesecondsFromGMTForDate:date];///手機(jī)當(dāng)前時(shí)區(qū)與格林威治時(shí)間的時(shí)間差
? ? ? ? ? ? NSTimeZone *bjTimerZone = [NSTimeZone timeZoneWithName:@"GMT+0800"];///此處以北京時(shí)區(qū)為例,可更換為GMT-0800等時(shí)區(qū)
? ? ? ? ? ? NSIntegerbjOffset = [bjTimerZone secondsFromGMTForDate:date];///北京時(shí)間與格林威治時(shí)間的時(shí)間差
? ? ? ? ? ? NSDate*localDate = [date dateByAddingTimeInterval:bjOffset - offset];///計(jì)算北京時(shí)間的date
? ? ? ? ? ? NSDateFormatter *format=[[NSDateFormatter alloc] init];
? ? ? ? ? ? [format setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
? ? ? ? ? ? NSString*dateStr?=[format stringFromDate:localDate];///拿到北京時(shí)區(qū)的時(shí)間戳
比如當(dāng)前時(shí)區(qū)為東京時(shí)間2018-8-8 18:38:38,我們開發(fā)一般需要北京時(shí)間评凝,因?yàn)榇嬖谝恍r(shí)時(shí)差,那么根據(jù)上述代碼就會(huì)得到正確的北京時(shí)間為 2018-8-8 17:38:38