//當前日前日期
NSDate *today = [NSDate date];
//時區
NSTimeZone *zone = [NSTimeZone systemTimeZone];
//設置間隔
_interval = [zone secondsFromGMTForDate: today];
//今天+8小時(中國上海時區)
today = [today dateByAddingTimeInterval: _interval];
//獲取明天日期
NSDate *tomorrowDate = [[NSDate alloc]initWithTimeInterval:24 * 60 * 60 sinceDate:[NSDate date]];
//日歷
NSCalendar *calendar = [NSCalendar currentCalendar];
//comps裡可以分離出時間年月日等信息
NSDateComponents *comps = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekCalendarUnit | NSWeekdayCalendarUnit |NSWeekdayOrdinalCalendarUnit | NSHourCalendarUnit) fromDate:tomorrowDate];
//獲取當前星期幾
NSInteger weekday = [comps weekday];
//將NSString類型轉換成NSDate
NSDate *serverDate = [dateFomatter dateFromString:serverTimeStr];
NSDate *createDate = [dateFomatter dateFromString:createTimeStr];
//算出兩個Date的間隔
NSTimeInterval betweenTime = [serverDate timeIntervalSinceDate:createDate];
NSDateFormatter *dateFomatter = [[NSDateFormatter alloc]init];
[dateFomatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//將string換成formatter形式
NSDate *stringDate = [dateFomatter dateFromString:string];
//formatter為月和日
[dateFomatter setDateFormat:@"MM-dd"];
//提取字符串中月和日
NSString *str1 = [dateFomatter stringFromDate:stringDate];