Best way to convert summary minutes to HH: mm format?

I get the return value from the web service in minutes, for example 538 minutes. I need to break this down into a few hours and minutes. What is the fastest way in .net code as well as VB6 code (two applications use the service) to convert this from minutes to HH: mm?

thanks

+7
math vb6
source share
6 answers

This code should work in both .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 verification):

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

Hope this helps!

+12
source share

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 
+5
source share

In VB6, you can simply use Format(538/1440.0, "hh:mm")

VB6 Date values ​​can be considered as the number of days, and 1440 minutes per day. So 538/1440 is the number of days in your period, and then you can use Format

+5
source share

Take module 60, then divide it by 60.

In VB, integer division uses \ .

+3
source share

If you need to perform operations on other DateTime objects, it may be useful to use a TimeSpan object, for example,

  Dim oTS As New TimeSpan(0, 538, 0) MessageBox.Show(Format(oTS.Hours, "00") & ":" & Format(oTS.Minutes, "00")) Dim startime As DateTime = Date.Now Dim newtime As DateTime = startime + oTS MessageBox.Show(newtime.ToString("HH:mm")) 

If not, then Matthew's suggestion about using integer division '\' and modulo 'Mod' will work very well.

+2
source share

if you need strings: dt.ToString ("HH: mm");

(information)

0
source share

All Articles