---
title: "How to Add two HH:mm:ss in iOS?"  
description: "How to Add two HH:mm:ss in iOS?"  
author: "Elena Glibart"  
published: 2014-10-28  
updated: 2014-10-28  
canonical: https://www.mindstick.com/forum/2447/how-to-add-two-hh-mm-ss-in-ios  
category: "iphone"  
tags: ["iphone", "ios", "ios 7"]  
reading_time: 2 minutes  

---

# How to Add two HH:mm:ss in iOS?

I tried to look for all possible [answers](https://www.mindstick.com/forum/156899/salesforce-marketing-cloud-interview-questions-answers) but could not find how to [add two](https://www.mindstick.com/forum/480/add-two-number) times in "HH:mm:ss" [format](https://www.mindstick.com/forum/162083/how-to-convert-ost-files-into-pst-format).

I have couple of captured times in an [array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net) and I want to return [sum](https://www.mindstick.com/forum/159332/how-can-i-use-sum-in-linq) of all in HH:mm:ss format as Here is my [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):

```
-(void) addTime{   NSMutableArray *recordedArray = [[NSMutableArray alloc]   initWithObjects:@"00:45:12",@"20:08:15",@"00:09:36",@"00:50:20", nil];   double sumOne = 0;   for (NSNumber * n in recordedArray)   {     sumOne += [n doubleValue];   }   NSLog(@"Sum of array time in HH:mm:ss is--> %f", sumOne);}
```

## Replies

### Reply by Anonymous User

I got it right here. Was little work but was worth it. Please optimise the code your way before using.\

```
-(void) addTime {    NSMutableArray *recordedArray = [[NSMutableArray alloc] initWithObjects:@"00:00:24",@"00:08:12",@"00:09:36",@"01:30:25", nil];    captureAllSecondsArray = [[NSMutableArray alloc] init];// Define NSMutableArray * captureAllSecondsArray in your .h file.    for (int i = 0; i<[recordedArray count]; i++)    {      [captureAllSecondsArray addObject:[self dateToSecondConvert:[recordedArray objectAtIndex:i]]];    }     int sumOfArray = 0;     for (NSNumber * n in captureAllSecondsArray)     {       sumOfArray += [n intValue];     }     NSString *iCanUseThis= [NSString stringWithFormat:@"%@", [self timeFormatted:sumOfArray]];     NSLog(@"Sum of array time in HH:mm:ss is--> %@",iCanUseThis); } - (NSNumber *)dateToSecondConvert:(NSString *)string  {    NSArray *components = [string componentsSeparatedByString:@":"];    NSInteger hours   = [[components objectAtIndex:0] integerValue];    NSInteger minutes = [[components objectAtIndex:1] integerValue];    NSInteger seconds = [[components objectAtIndex:2] integerValue];    NSNumber *secondsNumber = [NSNumber numberWithInteger:(hours * 60 * 60) + (minutes * 60) + seconds];    return secondsNumber;  }- (NSString *)timeFormatted:(int)totalSeconds {   int seconds = totalSeconds % 60;   int minutes = (totalSeconds / 60) % 60;   int hours = totalSeconds / 3600;   NSString *totalTime = [NSString stringWithFormat:@"%02d:%02d:%02d",hours, minutes, seconds];   return totalTime; }
```


---

Original Source: https://www.mindstick.com/forum/2447/how-to-add-two-hh-mm-ss-in-ios

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
