Q:

C# program to find the difference of two specified times using TimeSpan

0

C# program to find the difference of two specified times using TimeSpan

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to find the difference of two specified times using the TimeSpan class is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to find the difference of two specified times using TimeSpan.

using System;

class Demo
{
    static void Main()
    {
        TimeSpan time;

        TimeSpan ts1 = new TimeSpan(10, 20, 50);
        TimeSpan ts2 = new TimeSpan(8, 19, 32);

        time = ts1 - ts2;

        Console.WriteLine("Hours:{0}, Minutes:{1}, Seconds:{2}",time.Hours,time.Minutes,time.Seconds);
    }
}

Output:

Hours:2, Minutes:1, Seconds:18
Press any key to continue . . .

Explanation:

Here, we created a class Demo that contains the Main() method. In the Main() method, we created the two time-spans with a specified time.

time = ts1 - ts2;

Using the above statement, we calculated the difference with two time-span and then we printed the result on the console screen.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now