I am trying to get a timer to start from 00:00:00 (minutes:seconds:milliseconds) and count up. I found this and this but I can't get it to quite work, it displays the current time and date.
My code is as follows:
- (void)timerTicked:(NSTimer *)timer
{
NSDate *date = [NSDate date];
unsigned int flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSCalendar* calendar = [NSCalendar currentCalendar];
NSDateComponents* components = [calendar components:flags fromDate:date];
NSDate* dateOnly = [[calendar dateFromComponents:components] dateByAddingTimeInterval:[[NSTimeZone localTimeZone]secondsFromGMT]];
static NSDateFormatter *dateFormatter;
if (!dateFormatter) {
dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"mm:ss:SS";
}
self.timerLabel.text = [dateFormatter stringFromDate:dateOnly];
}