- (void)TimerCount
{
CountNumber++;
NSString *time = [[NSString alloc] init];
NSUInteger seconds = CountNumber;
NSUInteger minutes = 0;
NSUInteger hours = 0;
if (seconds > 59) {
seconds -= 60;
minutes++;
if (seconds < 10) {
time = [NSString stringWithFormat:@":0%i",seconds];
} else time = [NSString stringWithFormat:@":%i",seconds];
}
if (minutes > 59) {
minutes -= 60;
hours++;
if (minutes < 10) {
time = [NSString stringWithFormat:@":0%i%@",minutes,time];
} else time = [NSString stringWithFormat:@":%i%@",minutes,time];
}
if (hours < 10) {
time = [NSString stringWithFormat:@"0%i%@",hours,time];
} else time = [NSString stringWithFormat:@"%i%@",hours,time];
}
NSString *time is the time.
Also NSTimer to call this method every second:
NSTimer *counterTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(timerCount)
userInfo:nil
repeats:YES];