Hi!
I want to convert myString - 60:00:00 to timespan
when I try TimeSpan.Parse(myString) the output is - 60.00:00:00
not sure why it is that format, need it to be just the 60 hours 0 minutes and 0 seconds
Can anyone help me with this?
The hours component, must be between 0 and 23. Because of this, passing “23:00:00” to the Parse method returns a time interval of 23 hours. On the other hand, passing “24:00:00” returns a time interval of 24 days. Because “24” is outside the range of the hours component, it is interpreted as the days component.
So if you want just 60 hours, you need to try TimeSpan.Parse(“2.12:00:00”).
TimeSpan.Parse method fails greater 24 hour, because TimeSpan variable cannot have hour over 24, as @wusiyangjia mentioned.
Can you try the following?
text = "60:00:00"
match = System.Text.RegularExpressions.Regex.Match(text,"(\d+):(\d+):(\d+)")
ts = New TimeSpan(0,Int32.Parse(match.Groups(1).Value),Int32.Parse(match.Groups(2).Value),Int32.Parse(match.Groups(3).Value))
if you want to get 60 (hour), ts.Hours+ts.Days*24 returns it.
Check this below code, @mimuhrin
Split(“60:00:00”,“:”)(0)+" hours “+Split(“60:00:00”,”:“)(1)+” minutes “+Split(“60:00:00”,”:“)(2)+” seconds "
Hope this may help you