Im trying to know if a date is in between other 2. The tricky thing is that these dates are just formed by a weekday and time. To do so, and skip previous problems, I took the very first weekdays, those are January 1970. So I take the current weekday and make it from 1970, like this:
NSDate *dateNow = [NSDate date];
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
I compare this date with fix dates (weekday and time) and look it it’s in any interval, like this:
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]);
but this is the output
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
Any ideas? Why is 0, always? I print the dates before calculting the timeIntervalSinceDate and it looks fine…
NSTimeIntervalis a floating point number. You have to use the%fformat specifier to log these values.