TimeSpan.Parse time format hhmmss

后端 未结 6 1502
忘掉有多难
忘掉有多难 2020-12-15 20:52

in c# i have time in format hhmmss like 124510 for 12:45:10 and i need to know the the TotalSeconds. i used the TimeSpan.Parse(\"12:45:10\").ToTalSeconds but it does\'nt tak

6条回答
  •  伪装坚强ぢ
    2020-12-15 21:30

    If you can guarantee that the string will always be hhmmss, you could do something like:

    TimeSpan.Parse(
        timeString.SubString(0, 2) + ":" + 
        timeString.Substring(2, 2) + ":" + 
        timeString.Substring(4, 2)))
    

提交回复
热议问题