objective c - timeIntervalSinceDate根据日期没有返回正确的值?

时间:2012-01-30 09:02:28

标签: objective-c nstimeinterval

对于某些值,以下代码段不会返回正确的值。它将当前时间与手机中保存的其他2个日期进行比较。它确实在早期工作,但是我们说它早上2点48分它没有......

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en"] autorelease]];
[dateFormatter setDateFormat:@"EEEE HH:mm dd-MM-y"];    
NSString *dateString = [dateFormatter stringFromDate:self.fechaInicio];

NSLog(@"La date start es: %@", dateString);
    //PRINTS : La date start es: Monday 22:00 05-01-1970

dateString = [dateFormatter stringFromDate:self.fechaFin];

NSLog(@"La Date end es: %@", dateString);
dateString = [dateFormatter stringFromDate:testDate];
    //PRINTS : La Date end es: Monday 05:00 05-01-1970

NSLog(@"DAte inside es: %@", dateString);
//PRINTS : DAte inside es: Monday 02:52 05-01-1970
NSLog(@"time interval nicio: %g", [testDate timeIntervalSinceDate:self.fechaInicio]);
    //PRINTS : time interval nicio: -68852
NSLog(@"time interval fin: %g", [testDate timeIntervalSinceDate:self.fechaFin]);
//PRINTS : time interval fin: -7652

return ([testDate timeIntervalSinceDate:self.fechaInicio] > 0 &&
        [testDate timeIntervalSinceDate:self.fechaFin] < 0);

所有日期都是在1970年,我是故意这样做的,因为我只需要在工作日之间进行比较,所以我将它们设置为同一年和月。

我很失落,因为它在午夜之前工作了几个小时,但它不适用于以后。

感谢。

0 个答案:

没有答案