-3

我想在 c#.net 中添加两个以上的时间值如何?例子:

129:43:50 + 20:20:00 + 30:00:10 = 180:04:00

4

4 回答 4

2

Maybe using TimeSpan.Add? This really is an odd question though.

EDIT:

Based on your comment I suggest you take a look at Standard TimeSpan Format Strings and Custom TimeSpan Format Strings on MSDN to see how you can format the TimeSpan.

于 2013-01-29T13:30:53.240 回答
2

如果你有List<TimeSpan>你可以使用 LINQ:

List<TimeSpan> times = new List<TimeSpan>();

TimeSpan total = times.Aggregate(new TimeSpan(), (t1, t2) => t1 + t2);

然后,对于格式化使用:

string result = string.Format ("{0:00}:{1:00}:{2:00}", (int)total .TotalHours, total.Minutes, total.Seconds);
于 2013-01-29T13:34:17.087 回答
0

How about the method

public DateTime Add(TimeSpan value)

? Its fairly the first result on google.

于 2013-01-29T13:30:41.483 回答
0

您将要使用TimeSpan对象。您需要构造,然后将这些值相加。

于 2013-01-29T13:32:07.987 回答