Home »
VB.Net »
VB.Net Programs
VB.Net program to print the difference of two times
Here, we are going to learn how to print the difference of two times in VB.Net?
Submitted by Nidhi, on January 19, 2021
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 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 »
TOP Interview Coding Problems/Challenges