获取当前时间的n秒后的时间:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSDate *nowDate = [NSDate date];
NSString *currentTimeStr = [formatter stringFromDate:nowDate];//2022-08-30 11:11:58
NSLog(@"目前时间==%@",currentTimeStr);
// n秒后时间
NSDate *afterDate = [NSDate dateWithTimeInterval:n sinceDate:nowDate];
NSString *afterTime = [formatter stringFromDate:afterDate];
NSLog(@"之后时间==%@",afterTime);
若需要之前时间,在n之前加个“-”
网友评论