有兩種方式解決這個問題
1、轉(zhuǎn)化為當(dāng)前自己想要的北京時間
//獲取本地時區(qū)
NSTimeZone *tZone = [NSTimeZone localTimeZone];
//? ? 獲取日歷
NSCalendar *calendar = [NSCalendar currentCalendar];
//獲取系統(tǒng)當(dāng)前時間
NSDate *currentDate = [NSDate date];
//設(shè)置日歷的時區(qū)
[calendar setTimeZone:tZone];
//取出當(dāng)前的時分秒
NSDateComponents *currentTime = [calendar components:NSCalendarUnitSecond|NSCalendarUnitMinute|NSCalendarUnitHour|NSCalendarUnitTimeZone fromDate:currentDate];
2夕春、發(fā)現(xiàn)從日歷中取出的時間日期不對专挪,實際上iOS默認時間是????時間(誰讓蘋果是人家美國公司呢)。當(dāng)我們把日歷取出的時間轉(zhuǎn)化為String類型時寨腔,時間就默認為當(dāng)前北京時間啦
[[Utility dateFormatter] stringFromDate:date]迫卢;
+ (NSDateFormatter *)dateFormatter
{
static NSDateFormatter *dateFormatter;
if(!dateFormatter){
dateFormatter = [NSDateFormatter new];
dateFormatter.dateFormat = @"yyyy-MM-dd";
}
return dateFormatter;
}