I need to be able to convert elapsed seconds to hours, minutes and seconds.
Wandering about the web, I found a VB6 solution to the problem.
I modified it to work in .NET thus:
Code in Timer:
Code in Function:VB Code:
Static stop_time As DateTime Dim elapsed_time As TimeSpan ' build elapsed time for display stop_time = Now elapsed_time = stop_time.Subtract(start_time) lblElapsed.Text = TimeString(elapsed_time.TotalSeconds)
I suppose I could be happy with this, but I would think that this age-old problem has probably been solved more eloquently with the dawn of the .NET Framework.VB Code:
Public Function TimeString(ByVal afSeconds As Double) As String Dim pfHrs As Double Dim pfMinutes As Double Dim pfSeconds As Double pfSeconds = afSeconds pfHrs = Int(pfSeconds / 3600) pfMinutes = (Int(pfSeconds / 60)) - (pfHrs * 60) pfSeconds = Int(pfSeconds Mod 60) If pfSeconds = 60 Then pfMinutes += 1 pfSeconds = 0 End If If pfMinutes = 60 Then pfMinutes = 0 pfHrs += 1 End If Return pfHrs.ToString("00") & ":" & pfMinutes.ToString("00") & ":" & pfSeconds.ToString("00") End Function
Anyone know how?




Reply With Quote