c#.netに3つ以上の時間値を追加したいのですが?例:
129:43:50 + 20:20:00 + 30:00:10 = 180:04:00
たぶん使用TimeSpan.Add
?これは本当に奇妙な質問ですが。
編集:
あなたのコメントに基づいて、MSDNのStandard TimeSpan Format StringsとCustom TimeSpan Format StringsTimeSpan
を見て、 をフォーマットする方法を確認することをお勧めします。
あなたが持っている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);
How about the method
public DateTime Add(TimeSpan value)
? Its fairly the first result on google.
TimeSpanオブジェクトを使用する必要があります。構築してから、値を追加する必要があります。