I have a 7 string in this format 00:00:00
Im trying to use timespan to calculate those strings
the problem is it counts it with days
Dim l1 As String = "14:32:45"
Dim l2 As String = "07:43:13"
Dim l3 As String = "00:00:00"
Dim l4 As String = "00:00:00"
Dim l5 As String = "18:34:54"
Dim l6 As String = "00:00:00"
Dim l7 As String = "12:00:34"
Dim ts1 As TimeSpan = TimeSpan.Parse(l1)
Dim ts2 As TimeSpan = TimeSpan.Parse(l2)
Dim ts3 As TimeSpan = TimeSpan.Parse(l3)
Dim ts4 As TimeSpan = TimeSpan.Parse(l4)
Dim ts5 As TimeSpan = TimeSpan.Parse(l5)
Dim ts6 As TimeSpan = TimeSpan.Parse(l6)
Dim ts7 As TimeSpan = TimeSpan.Parse(l7)
Dim ttsum As New TimeSpan
ttsum = ts1 ts2 ts3 ts4 ts5 ts6 ts7
MsgBox(ttsum.ToString)
Output : 2.04:51:26
Desired output : 52:51:26
CodePudding user response:
That's the way a TimeSpan
works. If you don't want the output of TimeSpan.ToString
then don't use it. You can do your own calculation of the number of hours and use that:
MessageBox.Show($"{Convert.ToInt32(ttsum.TotalHours)}:{ttsum.Minutes:00}:{ttsum.Seconds:00}")