平均时间跨度转换错误
本文关键字:错误 转换 时间跨度 | 更新日期: 2023-09-27 18:06:22
我在。csv文件中有一些数据,看起来像这样:
1, task1, 00:00:02.0000000
1, task2, 00:00:00.3529381
1, task3, 00:00:01.1604731
1, task4, 00:00:00.1413738
第三列是TimeSpans。我需要计算它们的平均值,最小值,最大值等等。我在尝试在线方法的问题是,它回来作为0。我试过:
public Log(string a_action, string a_time, string a_executionTime, string a_studentLogin)
{
Action = a_action;
Time = a_time;
ExecutionTime_s = a_executionTime;
ExecutionTime_ts = TimeSpan.ParseExact("0:0", @"h':m",
CultureInfo.InvariantCulture);
ExecutionTime_l = Convert.ToInt64(ExecutionTime_ts.TotalMilliseconds);
ExecutionTime_d = (double)ExecutionTime_ts.TotalMilliseconds;
}
public void Calc()
{
List<Log> logList = CSVToList.GetList();
double doubleAverageTicks = logList.Average(timeSpan => timeSpan.ExecutionTime_d);
long longAverageTicks = Convert.ToInt64(doubleAverageTicks);
TimeSpan sp = new TimeSpan(longAverageTicks);
}
TimeSpan sp = TimeSpan.FromMilliseconds(doubleAverageTicks);