I am struggling with updating UILabel for count down for that I use following code
- (void)updateLabel {
// convert date string to date then set to a label
NSDateFormatter *dateStringParser = [[NSDateFormatter alloc] init];
[dateStringParser setDateFormat:@"MM/dd/yyyy"];
NSLog(@"date from update label %@", _selectedBirthdate);
//OUTPUT date from update label 07/23/2013
NSDate *date = [dateStringParser dateFromString:_selectedBirthdate];
NSLog(@"date from update label %@", date);
NSTimeInterval timeInterval = [date timeIntervalSinceNow]; ///< Assuming this is in the future for now.
NSString *stringVariable = [self stringFromTimeInterval:timeInterval];
self.dayLable.text = [NSString stringWithFormat:@"%@", stringVariable];
self.hourLable.text = [NSString stringWithFormat:@"%@", stringVariable];
self.minutesLable.text = [NSString stringWithFormat:@"%@", stringVariable];
// i want to update this day hour minutes lable like this much of days hour and minutes remaining
NSLog(@"%@",stringVariable);
}
I use following method for counting days hours and minutes but I dont know whats the logic mind is not working here how to find days hours and minutes from interval
- (NSString *)stringFromTimeInterval:(NSTimeInterval)interval {
NSInteger ti = (NSInteger)interval;
NSLog(@"%d",ti);
// NSInteger seconds = ti % 60;
NSInteger days = (ti * 60);
NSInteger minutes = (ti / 60) % 60;
NSLog(@"%d",minutes);
NSInteger hours = (ti / 3600);
NSLog(@"%d",hours);
return [NSString stringWithFormat:@"%02i hours : %02i min", hours, minutes];
}