草庐IT

TimeSpans

全部标签

c# - 查找 TimeSpans 集合的平均值

我有TimeSpans的集合,它们代表完成一项任务所花费的时间。现在我想找出花在该任务上的平均时间。这应该很容易,但出于某种原因,我没有得到正确的平均值。这是我的代码:privateTimeSpan?GetTimeSpanAverage(ListsourceList){TimeSpantotal=default(TimeSpan);varsortedDates=sourceList.OrderBy(x=>x);foreach(vardateTimeinsortedDates){total+=dateTime;}returnTimeSpan.FromMilliseconds(total.

c# - 将 TimeSpan 格式化为 mm :ss for positive and negative TimeSpans

我正在寻找.net3.5中的解决方案,我编写了以下工作解决方案:privatestringFormatTimeSpan(TimeSpantime){returnString.Format("{0}{1:00}:{2:00}",time但我的问题是:有没有更好的方法?也许在我不需要辅助函数的地方更短。 最佳答案 略短,使用CustomTimeSpanFormatStrings:privatestringFormatTimeSpan(TimeSpantime){return((time 关于