开发者

Cast String to TimeSpan

I tried to parse string to TimeSpan like the following :

    Dim dt As DateTime = DateTime.Now
    Dim timeCheckin As String = Format(dt, "HH:MM:FF")
    ts = TimeSpan.Parse(timeCheckin)

It threw error like this:

System.OverflowException: The TimeSpan could not be parsed 开发者_运维知识库because at least one of the hours, minutes, or seconds components is outside its valid range.

Can anyone give me a suggestion? Thank you.


The parameter for TimeSpan.Parse must be in format hh:mm:ss, not hh:mm:ff

The format is [ws][-][d.]hh:mm:ss[.ff][ws]

hh:mm:ss are required, the others are optional

Dim timeCheckin As String = Format(dt, "HH:mm:ss")
ts = TimeSpan.Parse(timeCheckin)


Are you really trying to parse hours, months and fractions of seconds?

Your format string should probably be something like HH:mm:ss instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜