Home > Article > Backend Development > C# program to add two time spans
First, set up two TimeSpans -
TimeSpan t1 = TimeSpan.FromMinutes(1); TimeSpan t2 = TimeSpan.FromMinutes(2);
To add it, use the Add() method -
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); // Adding TimeSpan res = t1.Add(t2); Console.WriteLine("Resultant TimeSpan: "+res); } }
The above is the detailed content of C# program to add two time spans. For more information, please follow other related articles on the PHP Chinese website!