我正在通过查询字符串传递一个字符串作为时间单位。但是当我尝试将字符串解析为时间跨度对象时,我会收到一个 System.FormatException' occurred in mscorlib.ni.dll but was not handled in user code
的错误,我猜测这意味着我格式化字符串的方式存在问题。
if (NavigationContext.QueryString.ContainsKey("workTimeSpanPkr"))
{
testString = NavigationContext.QueryString["workTimeSpanPkr"];
//Assign text box string value to a test time span variable.
testTm = TimeSpan.ParseExact(testString, @"hh\ \:\ mm\ \:\ ss", CultureInfo.InvariantCulture);
}
当我通过调试器运行时传递给
testString
的字符串是:"00:15:04"。
有人知道解析小时、分钟和秒的正确格式吗?这是我正在尝试解析的值和我使用的代码:
![format exception](https://istack.dev59.com/vxlfV.webp)
![value of work string](https://istack.dev59.com/GYiHX.webp)
TimeSpan.Parse
或TimeSpan.TryParse
。 - MikeH