Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa touch 比较nstimer选择器中的日期_Cocoa Touch_Ios_Datetime_Nsdate - Fatal编程技术网

Cocoa touch 比较nstimer选择器中的日期

Cocoa touch 比较nstimer选择器中的日期,cocoa-touch,ios,datetime,nsdate,Cocoa Touch,Ios,Datetime,Nsdate,我正在编写一个countdowtimer应用程序,就像iPhone时钟应用程序中的计时器选项卡一样。现在我很难比较日期,“现在”和“未来日期”。 所有变量都是合成的,并且是非原子的和保留的。 我现在有这个密码 - (IBAction)startTimer:(id)sender { NSLog(@"startTimer"); pickerView.hidden = YES; labelView.hidden = NO; now = [[NSDate alloc]

我正在编写一个countdowtimer应用程序,就像iPhone时钟应用程序中的计时器选项卡一样。现在我很难比较日期,“现在”和“未来日期”。 所有变量都是合成的,并且是非原子的和保留的。 我现在有这个密码

- (IBAction)startTimer:(id)sender {
    NSLog(@"startTimer");
    pickerView.hidden = YES;
    labelView.hidden  = NO;
    now = [[NSDate alloc] init];
    futureDate = [[NSDate alloc] initWithTimeInterval:picker.countDownDuration sinceDate:now];
    NSLog(@"Dates.\nNow = (%@)  \nfutureDate (%@)", now, futureDate);
    timerLabelUpdater = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(labelUpdater) userInfo:nil repeats:YES];
}

- (void)labelUpdater {
    if ([now timeIntervalSinceDate:futureDate] < 0.0) {
        NSLog(@"YES\nDates.\nNow = (%@)  \nfutureDate (%@)", now, futureDate);
    } else {
        NSLog(@"NO\nNow = (%@)  \nfutureDate (%@)", now, futureDate);
    }
}
调试器信息: 2011-02-08 16:46:02.449 App[22504:207]startTimer 2011-02-08 16:46:02.451应用程序[22504:207]日期。 现在=2011-02-08 18:46:02+0000 未来日期2011-02-08 18:47:02+0000 2011-02-08 16:46:03.451 App[22504:207]是

它永远给我“是”。
但是如果你看到可变的小时数,与我的时钟时间相比,它们在未来是+2h。这是错误吗?

很抱歉,如果我测试的日期错误,比较变量now和futureDate,时间间隔将永远相同。在测试中,我将now变量替换为[[NSDate alloc]init]。现在代码可以工作了

if ([[[NSDate alloc]init] timeIntervalSinceDate:futureDate] < 0.0) {
    NSLog(@"YES\nDates.\nNow = (%@)  \nfutureDate (%@)", now, futureDate);
} else {
    NSLog(@"NO\nNow = (%@)  \nfutureDate (%@)", now, futureDate);
}
对不起,我问了个愚蠢的问题