1.把当前时间转为字符串 (NSDate与北京时间相隔8小时,格式化之后就是北京时间)
NSDate *date = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
[dateFormat setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
NSString *dateStr = [dateFormat stringFromDate:date];
NSLog(@"当前时间:%@",dateStr);
2.获取当前时间的Day
+ (NSInteger)getCurrentDay{ NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:[NSDate date]];
NSInteger currentDay = [components day];
return currentDay;
}