I'm trying to make a counter that shows the number of days until we go on a trip to Europe. Its only about 70 days (as of today), so I do not believe that I will need to worry about astronomically large quantities or something else, but I'm really at a dead end - I attached a code that some friends gave me that also do not work. Believe me, when I say that I tried everything I could think of - and before anyone bites my head, what I saw in these forums, yes, I looked very hard at the Apple Documentation, however Im not at 100 % sure where to start - I tried NSTimer, NSDate and all their subclasses and methods, but theres nothing that jumps immediately.
In terms of what, in my opinion, I should do, I think I need to somehow assign an integer value to the "day" today / now / current day, which will be dynamically changed with [NSDate date], and then the same in the day we leave. The countdown is simply updated when the method is called again (I can do it with NSTimer if necessary), and the value displayed on the countdown is the difference between the two values.
I especially don't want to have a blinking thing that updates every second until we leave - personally, I think it's sticky, but if anyone knows how then Id would appreciate it for future reference.
Ive also done an extensive google search, and I can just use the wrong search terms, but I also can not find anything there.
Any help is greatly appreciated.
.
Michaeljvdw
- (void)countDownMethod {
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setDay:startDay];
[comps setMonth:startMonth];
[comps setYear:startYear];
[comps setHour:startHour];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *date = [gregorian dateFromComponents:comps];
NSLog(@"%@",date);
[gregorian release];
[comps release];
NSTimeInterval diff = [date timeIntervalSinceNow];
int diffInt = diff;
NSString *days = [NSString stringWithFormat:@"%d",diffInt/86400];
day0.text = @"0";
day1.text = @"0";
day2.text = @"0";
NSLog(@"Days Length: %d",days.length);
if(days.length >= 1){
day2.text = [days substringFromIndex:days.length - 1];
if(days.length >= 2){
day1.text = [days substringWithRange:NSMakeRange(days.length - 2, 1)];
if(days.length >= 3){
day0.text = [days substringWithRange:NSMakeRange(days.length - 3, 1)];
}
}
}
NSString *hours = [NSString stringWithFormat:@"%d",(diffInt%86400)/3600];
hour0.text = @"0";
hour1.text = @"0";
NSLog(@"Hours Length: %d",hours.length);
if(hours.length >= 1){
hour1.text = [hours substringFromIndex:hours.length - 1];
if(hours.length >= 2){
hour0.text = [hours substringWithRange:NSMakeRange(hours.length - 2, 1)];
}
}
NSString *minutes = [NSString stringWithFormat:@"%d",((diffInt%86400)%3600)/60];
minute0.text = @"0";
minute1.text = @"0";
NSLog(@"Minutes Length: %d",minutes.length);
if(minutes.length >= 1){
minute1.text = [minutes substringFromIndex:minutes.length - 1];
if(minutes.length >= 2){
minute0.text = [minutes substringWithRange:NSMakeRange(minutes.length - 2, 1)];
}
}
}