15,906,463 members
See more:
I have 3 time string as follows
C#
``` string s1="9";
string s2= "82";
string s3= "24";```

I want to add string currtime= s1+s2+s3;
but here s2 is more than 60 ,means minute is more than 60 then automatically add one hour.
I want time is like follow
C#
```string finalTime="10:22:24 AM"
```

For the same we use TIME function in excel. "=TIME(A1,B1,B3)"
how can we do this in c#.
Posted
Updated 18-Jan-16 19:50pm
v2
Sergey Alexandrovich Kryukov 19-Jan-16 1:16am
It all makes no sense. Working with strings representing data instead of data itself.
Even if you formulate it all properly, it will look quite trivial. What have you tried so far?
—SA
Member 12036327 19-Jan-16 1:38am
I had do silly coding, to check if minutes more than 60 then minus it from 60 then then add one our in hour. it works fine but I am looking for direct and easy way, If it is there any.

## Solution 1

The simple flow will like this.first add H M ans S as individually.then first divide second with 60 and add answer into minute and take remainder as your remain minute then divide minute with 60 and add answer into hour and take remainder as minute remain.
finally you get All H M ans S as answer.
NOTE : do all operation in integer format

v2

## Solution 2

There are basically two ways:
1. Do yourself the computation
2. Use TimeSpan[^] objects to perform the computation

In order to use both methods you have to:
• parse your strings into integers
• format your result into a string

See Int32.Parse Method (System)[^], Int32.ToString Method (String) (System)[^].

## Solution 3

C#
``` string s1 = "9";
string s2 = "82";
string s3 = "24";

long seconds = Convert.ToInt64(s3) + Convert.ToInt64(s2) * 60+Convert.ToInt64(s1)*3600;
DateTime startDateTime = DateTime.Today;
Console.WriteLine(date.ToString("hh:mm:ss tt", System.Globalization.CultureInfo.InvariantCulture));