How can i put the 2 times together And i want it to stay in the time format: hh:mm:ss
string time1 = "00:49:35";
string time2 = "00:31:34";
totaltime = time1 + time2;
This should be the result 01:21:09 (1 hour and 21 min and 09 sec)
How can i put the 2 times together And i want it to stay in the time format: hh:mm:ss
string time1 = "00:49:35";
string time2 = "00:31:34";
totaltime = time1 + time2;
This should be the result 01:21:09 (1 hour and 21 min and 09 sec)
How about using the TimeSpan class:
TimeSpan time1 = TimeSpan.Parse("00:49:35");
TimeSpan time2 = TimeSpan.Parse("00:31:34");
TimeSpan res = time1 + time2;
Console.WriteLine(res.ToString()); // 01:21:09, you may omit the ToString() call
If you don't want to Parse
a string, you can construct a TimeSpan
object:
TimeSpan time1 = new TimeSpan(00, 49 ,35);
TimeSpan time2 = new TimeSpan(00, 31 ,34);
TimeSpan res = time1 + time2;
Console.WriteLine(res); // 01:21:09
This works for me:
(TimeSpan.Parse(time1) + TimeSpan.Parse(time2)).ToString()