NSDate API
获取当前时间
获取时间戳
创建间隔指定时间戳的Date
// 获取昨天
NSTimeInterval time = 24 * 60 * 60;
NSDate *date = [NSDate dateWithTimeIntervalSinceNow: -time];
NSLog(@"%@", date);
// 明天
NSTimeInterval time = 24 * 60 * 60;
NSDate *tomorrowDate = [NSDate dateWithTimeIntervalSinceNow: time];
NSLog(@"%@", tomorrowDate);
比较两个时间
NSDate --> NSString
NSDate *nowDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
NSString *dateString = [dateFormatter stringFromDate:nowDate];
NSLog(@"%@", dateString);
NSString --> NSDate
NSString *timeStr = @"2018-09-10 15:24:51";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
NSDate *date = [dateFormatter dateFromString:timeStr];
NSLog(@"%@", date);
获取两个Date的间隔秒数