0
我想比较两个NSDates,一个是通过viewDidLoad方法创建的,另一个是通过单击按钮来创建的。我希望能够点击按钮并查找自viewDidLoad运行以来的时差。我一直得到零的差异。有任何想法吗?NSDate timeInterval = nil
#import "TimeViewController.h"
id startTime;
@implementation TimeViewController
- (void)viewDidLoad {
NSDate *startTime = [NSDate date];
NSLog(@"startTime = %@",startTime);
}
- (IBAction)buttonPressed{
NSDate *now = [NSDate date];
NSLog(@"now = %@",now);
double timeInterval = [now timeIntervalSinceDate:startTime];
NSLog(@"time difference = %@",[NSString stringWithFormat:@"%g",timeInterval]);
}