Best way to convert total minutes into HH:mm format?

This code should work both in .NET and VB6:

Dim hours As Integer = 538 \ 60
Dim minutes As Integer = 538 - (hours * 60)
Dim timeElapsed As String = CType(hours, String) & ":" & CType(minutes, String)
label1.Text = timeElapsed

In .NET exclusively, you should be able to do the following (which requires to be tested):

Dim timeElapsed As DateTime = New DateTime(1, 1, 1, 0, 538, 0)
label1.Text = timeElapsed.ToString("HH:mm")

I hope this helps!


In VB6 you could just use Format(538/1440.0, "hh:mm")

VB6 Date values can be treated as a number of days, and there's 1440 minutes in a day. So 538/1440 is the number of days in your period, and then you can use Format


In .Net you have a TimeSpan class so you can do the following

Dim t As New TimeSpan(0, 538, 0)

'Then you have the 2 properties
t.Hours
t.Minutes

Tags:

Vb.Net

Vb6

Math