To get the system uptime in C#, you can subtract the current time from the system startup time. Here's an example code that does this using the TimeSpan
class:
main.cs269 chars6 lines
The Environment.TickCount
property returns the tick count of the system since it started. The TimeSpan.FromMilliseconds
method converts this value to a TimeSpan
object. Finally, you can format the TimeSpan
object as a string to display it in a human-readable format.
gistlibby LogSnag