use*_*968 0 c# datetime winforms
我有一个字符串列表,以这种格式保存时间值:11:25:46.123,我希望能够从此列表中找到最高和最低时间值.我该怎么做?
我尝试过类似的东西,但我不确定它是否正确,我不知道接下来该做什么.
List<TimeSpan> time = StringList.Select(x => TimeSpan.ParseExact(x, "HH:mm:ss.fff", null)).ToList();
Run Code Online (Sandbox Code Playgroud)
编辑:我收到错误:
Input string was not in a correct format.
Run Code Online (Sandbox Code Playgroud)
我收到错误:输入字符串格式不正确.
您的时间跨度格式不正确.试试这个
var StringList = new[] { "21:25:46.123" };
List<TimeSpan> time = StringList
.Select(x => TimeSpan.ParseExact(x, @"hh\:mm\:ss\.fff", null))
.ToList();
var max = time.Max();
var min = time.Min();
Run Code Online (Sandbox Code Playgroud)