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