Get how long the computer has been running.
This function gives the programmer the ability to get a string representation of how long the computer has been running since the OS has started. The TickCount function is a value that has existed in the Windows API since Windows 2000.
VB.NET
''' <summary>
''' Get a human readable string representation of the
''' amount of time the computer has been on since the OS started.
''' </summary>
''' <returns>How long the computer has been running in days, hours
''' minutes and seconds.
''' </returns>
''' <remarks></remarks>
Public Function getUptime() As String
Dim strResult As String = String.Empty
strResult += Math.Round(Environment.TickCount / 86400000) & " days, "
strResult += Math.Round(Environment.TickCount / 3600000 Mod 24) & " hours, "
strResult += Math.Round(Environment.TickCount / 120000 Mod 60) & " minutes, "
strResult += Math.Round(Environment.TickCount / 1000 Mod 60) & " seconds."
Return strResult
End Function
' Example usage of this function.
MessageBox.Show(getUptime)
See Also
- </DIC> Submission - http://www.dreamincode.net/code/snippet1514.htm
page_revision: 0, last_edited: 1197780706|%e %b %Y, %H:%M %Z (%O ago)





