2011-11-23 120 views
0

我試圖知道日期是否在其他之間2.棘手的是,這些日期只是由工作日和時間形成。爲此,並跳過以前的問題,我花了第一個工作日,那些是1970年1月。所以我採取當前的工作日,並從1970年,如下所示: NSDate * dateNow = [NSDate date];timeIntervalSinceDate返回0

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; 
    [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en"] autorelease]]; 
    [dateFormatter setDateFormat:@"EEEE HH:mm"];  

    NSString *dateString = [dateFormatter stringFromDate:dateNow]; 

    NSLog(@"La fecha es: %@", dateString); 

    NSDate *dateComp = [dateFormatter dateFromString:dateString];//Date and time in 1970 

我比較這最新與修復時間(工作日和時間),看看它這是在任何時間間隔,就像這樣:

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); 

dateString = [dateFormatter stringFromDate:self.fechaFin]; 

NSLog(@"La Date end es: %@", dateString); 
dateString = [dateFormatter stringFromDate:testDate]; 

NSLog(@"DAte inside es: %@", dateString); 

NSLog(@"time interval nicio: %d", [testDate timeIntervalSinceDate:self.fechaInicio]); 
NSLog(@"time interval fin: %d", [testDate timeIntervalSinceDate:self.fechaFin]); 

但這是輸出

Palyque[746:307] La date start es: Monday 09:00 05-01-1970 
2011-11-23 11:34:47.857 Palyque[746:307] La Date end es: Monday 16:00 05-01-1970 
2011-11-23 11:34:47.861 Palyque[746:307] DAte inside es: Wednesday 11:34 07-01-1970 
2011-11-23 11:34:47.864 Palyque[746:307] time interval nicio: 0 
2011-11-23 11:34:47.867 Palyque[746:307] time interval fin: 0 

任何想法?爲什麼是0,總是?我在打印timeIntervalSinceDate之前打印日期,它看起來很好...

回答

2

NSTimeInterval是一個浮點數。您必須使用%f格式說明符來記錄這些值。