Imports System
Public Class TimeDiff
Private seconds As Integer
Private minutes As Integer
Private hours As Integer
Public Sub New()
End Sub
Public Sub New(ByVal hours As Integer, ByVal minutes As Integer, ByVal seconds As Integer)
Me.hours = hours
Me.minutes = minutes
Me.seconds = seconds
End Sub
Public Shared Function timeDifference(ByVal start As TimeDiff, ByVal _end As TimeDiff) As TimeDiff
Dim timediff As TimeDiff = New TimeDiff(0, 0, 0)
If start.seconds > _end.seconds Then
_end.minutes -= 1
_end.seconds += 60
End If
timediff.seconds = _end.seconds - start.seconds
If start.minutes > _end.minutes Then
_end.hours -= 1
_end.minutes += 60
End If
timediff.minutes = _end.minutes - start.minutes
timediff.hours = _end.hours - start.hours
Return timediff
End Function
Public Shared Sub Main(ByVal args As String())
Dim start As TimeDiff = New TimeDiff(7, 11, 25)
Dim _end As TimeDiff = New TimeDiff(11, 32, 17)
Dim timediff As TimeDiff = timeDifference(start, _end)
Console.Write("{0:D}:{1:D}:{2:D} - ", start.hours, start.minutes, start.seconds)
Console.Write("{0:D}:{1:D}:{2:D} ", _end.hours, _end.minutes, _end.seconds)
Console.Write("= {0:D}:{1:D}:{2:D}", timediff.hours, timediff.minutes, timediff.seconds)
End Sub
End Class
' run:
'
' 7:11:25 - 11:31:77 = 4:20:52
'