In objective-c, how can I convert an integer (representing seconds) to days, minutes, an hours?
Thanks!
You will get days,hours,minutes and seconds from total seconds(self.secondsLeft)
days = self.secondsLeft/86400;
hours = (self.secondsLeft %86400)/3600;
minutes = (self.secondsLeft % 3600) / 60;
seconds = (self.secondsLeft %3600) % 60;
Code ......
[NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(updateCountdown) userInfo:nil repeats: YES];
-(void) updateCountdown {
int days,hours,minutes,seconds;
self.secondsLeft--;
days = self.secondsLeft/86400;
hours = (self.secondsLeft %86400)/3600;
minutes = (self.secondsLeft % 3600) / 60;
seconds = (self.secondsLeft %3600) % 60;
NSLog(@"Time Remaining =%@",[NSString stringWithFormat:@"%02d:%02d:%02d:%02d",days, hours, minutes,seconds]);
}