如何使用 TimeSpan 将此格式 "hmmss" 中的持续时间字符串(例如“00047”)解析为秒数?

How to parse duration strings in this format "hmmss", example "00047" into seconds using TimeSpan?

请问我们如何使用 TimeSpan 将像“00047”这样的简单持续时间字符串解析为秒数?

TimeSpan.ParseExact("00047", "hmmss", Nothing).TotalSeconds

以上给出错误:"Input string was not in a correct format."

我正在从通话记录中解析时长

070615 1815 00047 9    9  806        00000000000       6103  807   80212  15  17           0     0                    
070615 1815 00155 7    9  806        00000000000       2206        41784      22           0     0                    
070615 1816 00249 7    9  806        00000000000       2206        41784      24           0     0   

这是 TimeSpan.ParseExact 的问题吗?

如果允许我们指定格式,例如hmmss,我们传递一个字符串 00047 直接映射到该格式 ...

如果您不接受有效格式,向我们询问格式有什么意义?

h 格式可以是一个或两个数字,因此它会尝试将其解析为两个数字并用完其余的数字。

您可以在字符串中添加零并使用 hh 格式:

TimeSpan.ParseExact("0" & "00047", "hhmmss", Nothing).TotalSeconds