【发布时间】:2013-08-03 05:47:03
【问题描述】:
我知道如何计算两个时间跨度之间的差异。 但是,我只能得到一个答案。毫秒、秒、分钟等
我想要的是比较两个时间跨度,然后得到以秒 + 毫秒为单位的差异。
意思是如果差是 10 秒和 309 毫秒,我会得到。
10.309 作为答案。
我不认为在这里显示我的任何代码真的很重要,因为我已经完成了所有工作,只是为了得到我想知道的结果。
如果您需要我的代码中的任何内容,请告诉。
TimeSpan first;
TimeSpan last;
TimeSpan.TryParseExact(First.Text.Replace("-", ":").Remove(First.Text.LastIndexOf("-"),1).Insert(First.Text.Length-4,"."),"g",CultureInfo.InvariantCulture,out first);
TimeSpan.TryParseExact(Last.Text.Replace("-", ":").Remove(First.Text.LastIndexOf("-"), 1).Insert(First.Text.Length - 4, "."), "g", CultureInfo.InvariantCulture, out last);
TimeSpan u = first - last;
MessageBox.Show(u.TotalMilliseconds.ToString());
【问题讨论】:
-
我不拒绝,我认为它不需要,抱歉忘记了,它是 c#,将添加它作为我的代码的标记和示例。
标签: c# compare timespan milliseconds seconds