0

对于某些值,以下代码段不会返回正确的值。它将当前时间与保存在手机中的 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 年,我是故意这样做的,因为我只需要在工作日之间进行比较,所以我将它们设置为相同的年份和月份。

我很迷茫,因为它在午夜前工作了几个小时,但以后就不行了。

谢谢。

4

0 回答 0