Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone: NSTimer Countdown (Display Minutes:Seconds)

I have my timer code set up, and it's all kosher, but I want my label to display "Minutes : seconds" instead of just seconds.

-(void)countDown{

    time -= 1;

    theTimer.text = [NSString stringWithFormat:@"%i", time];

    if(time == 0)
    {
    [countDownTimer invalidate];
    }
}

I've already set "time" to 600, or 10 minutes. However, I want the display to show 10:59, 10:58, etc. until it reaches zero.

How do I do this?

Thanks!

like image 646
user298261 Avatar asked Apr 13 '10 02:04

user298261


1 Answers

int seconds = time % 60;
int minutes = (time - seconds) / 60;
theTimer.text = [NSString stringWithFormat:@"%d:%.2d", minutes, seconds];
like image 72
Noah Witherspoon Avatar answered Sep 24 '22 12:09

Noah Witherspoon