Timespan无法解析 [英] Timespan could not be parsed
问题描述
我有一个持续时间的字符串列表。哪两个字符串 -
01:33:56:00,00:23:34:00
当我添加此列表值,我得到例外 -
无法解析TimeSpan,因为至少有一个数字组件超出范围或包含太多数字。
我正在使用它 -
I have a string list of time duration. which have two string-
"01:33:56:00","00:23:34:00"
When i adding this list value, i got exception-
The TimeSpan could not be parsed because at least one of the numeric components is out of range or contains too many digits.
I am using this-
olst.TotleQcDuration = olst.Reports.Aggregate(TimeSpan.Zero,(小计) ,t)=> subtotal.Add(TimeSpan.Parse(t.Duration)))。ToString();
我尝试过:
olst.TotleQcDuration = olst.Reports.Aggregate(TimeSpan.Zero, (subtotal, t) => subtotal.Add(TimeSpan.Parse(t.Duration))).ToString();
What I have tried:
olst.TotleQcDuration = olst.Reports.Aggregate(TimeSpan.Zero, (subtotal, t) => subtotal.Add(TimeSpan.Parse(t.Duration))).ToString();
推荐答案
试试 -
01:33:56:00而不是001:33:56:00
额外的0可能会导致问题。
希望,它有帮助:)
Try-
"01:33:56:00" instead of "001:33:56:00"
That extra 0 can cause the problem.
Hope, it helps :)
其中以及如何这些01:33:56:00,00:23:34:00存储了吗?
检查出来 TimeSpan.Parse方法(字符串)(系统) [ ^ ],特别注意备注下的参数格式
Where and how are these "01:33:56:00","00:23:34:00" stored?
Check this out TimeSpan.Parse Method (String) (System)[^], pay particular attention to the parameter format under Remarks
[ws][-]{ d | [d.]hh:mm[:ss[.ff]] }[ws]
Hi Mukesh,
您的第一个参数导致溢出异常。第一个冒号001:33:56:00之后的值是小时值,它必须小于24(你的是33)。请更正并使用Try-Catch捕获它:
Hi Mukesh,
Your first parameter is causing an overflow exception. The value after the first colon of "001:33:56:00" is an hour value and it must be less than 24 (yours is 33). Please correct it and trap it using Try-Catch:
try
{
olst.TotleQcDuration = olst.Reports.Aggregate(TimeSpan.Zero, (subtotal, t) => subtotal.Add(TimeSpan.Parse(t.Duration))).ToString();
}
catch (OverflowException)
{
MessageBox.Show("A value in the string exceeds a legitimate value.");
}
这篇关于Timespan无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!