How to convert hh:mm:ss to minutes in VB.NET

1 Answer

0 votes
Imports System

Class Program
	Public Shared Function HhmmssToMinutes(ByVal hhmmss As String) As Double
        Dim timeParts As String() = hhmmss.Split(":"c)
		
        Dim hours As Integer = Integer.Parse(timeParts(0))
        Dim minutes As Integer = Integer.Parse(timeParts(1))
        Dim seconds As Integer = Integer.Parse(timeParts(2))
        Return (hours * 60) + minutes + (seconds / 60.0)
    End Function

    Public Shared Sub Main()
        Console.WriteLine(HhmmssToMinutes("2:30:00"))
        Console.WriteLine(HhmmssToMinutes("2:35:30"))
        Console.WriteLine(HhmmssToMinutes("5:00:45"))
    End Sub
End Class


' run:
'
' 150
' 155.5
' 300.75
'

 



answered Apr 17, 2025 by avibootz

Related questions

1 answer 57 views
1 answer 132 views
1 answer 159 views
1 answer 163 views
1 answer 76 views
1 answer 96 views
1 answer 83 views
...