×

VB.Net Programs

VB.Net program to print the difference of two times

By Nidhi Last Updated : November 16, 2024

Difference of two times in VB.Net

Here, we will calculate the difference of two times and print the result on the console screen.

Program/Source Code:

The source code to print the difference of two times is given below. The given program is compiled and executed successfully.

VB.Net code to find the difference of two times

'VB.NET program to print the difference of two times.

Imports System

Module Module1
    Sub Main()
        Dim time As TimeSpan
        Dim ts1 As New TimeSpan(12, 20, 30)
        Dim ts2 As New TimeSpan(10, 20, 10)

        time = ts1 - ts2

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

Output

Hours:2, Minutes:0, Seconds:20
Press any key to continue . . .

Explanation

In the above program, we created a module Module1 that contains the Main() function. The Main() function is the entry point for the program.

In the Main() function, we created two objects of the TimeSpan class and initialized them with time values. After that, we calculated the difference between the two times and print the result on the console screen.

VB.Net Date & Time Programs »


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.