首先,设置两个TimeSpans-
TimeSpan t1 = TimeSpan.FromMinutes(1); TimeSpan t2 = TimeSpan.FromMinutes(2);
要添加它,请使用Add()
方法-
TimeSpan res = t1.Add(t2);
Using System; using System.Linq; public class Demo { public static void Main() { TimeSpan t1 = TimeSpan.FromMinutes(1); TimeSpan t2 = TimeSpan.FromMinutes(2); Console.WriteLine("First TimeSpan: "+t1); Console.WriteLine("Second TimeSpan: "+t2); //添加 TimeSpan res = t1.Add(t2); Console.WriteLine("Resultant TimeSpan: "+res); } }