NSDate
has an instance method timeIntervalSinceDate:
that returns an NSTimeInterval
.
When the first button is pressed, you can get the current data using [NSDate date]
and store it in a property named 'previousDate', and then when the second button is pressed: You can get the current data again and calculate the time interval that passed using the following code:
- (void)firstButtonTapped {
[self setPreviousDate:[NSDate date]];
}
- (void)secondButtonTapped {
NSTimeInterval timeInterval = [[NSDate date] timeIntervalSinceDate:[self previousDate]];
// timeInterval now contains the amount of time that passed in seconds
}