c# - Sum two dates represented in a hh:mm:ss string format -
this question has answer here:
- c# method sum hh:mm data ??? 1 answer
how can put 2 times , want stay in time format: hh:mm:ss
string time1 = "00:49:35"; string time2 = "00:31:34"; totaltime = time1 + time2;
this should result 01:21:09 (1 hour , 21 min , 09 sec)
how using 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, may omit tostring() call
if don't want parse
string, can construct 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
Comments
Post a Comment