我有一個包含多個屬性的XML文件,其中包含時間值,我需要將這些值相加。將時間值的字符串表示解析爲TimeSpan
<test>
<value time="0.345"/>
<value time="0.756"/>
<value time="0.455"/>
</test>
但問題是,TimeSpan.Parse("0.345")
不分析中的異常值和結果。使用TimeSpan.Parse("0.345",System.Globalization.CultureInfo.GetCultureInfo("en-us"))
的事件會導致例外。
Message
Die Zeichenfolge wurde nicht als gültiger TimeSpan erkannt.
StackTrace
bei System.Globalization.TimeSpanParse.TimeSpanResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument, String failureArgumentName)
bei System.Globalization.TimeSpanParse.ProcessTerminal_HM(TimeSpanRawInfo& raw, TimeSpanStandardStyles style, TimeSpanResult& result)
bei System.Globalization.TimeSpanParse.ProcessTerminalState(TimeSpanRawInfo& raw, TimeSpanStandardStyles style, TimeSpanResult& result)
bei System.Globalization.TimeSpanParse.TryParseTimeSpan(String input, TimeSpanStandardStyles style, IFormatProvider formatProvider, TimeSpanResult& result)
bei System.TimeSpan.Parse(String s)
那麼,什麼是正確的方法來解析TimeSpan的這些時間值,所以我可以總結這些值?
什麼是您的'CurrentCulture'? –
什麼是0.345?分鐘?秒? – faby
你需要指定那個時間屬性的單位是什麼? 0.345s,0.345h還是什麼? – cjb110