svetlozar_kirkov

Time Elapsed Since Last Boot (Exercise)

Oct 7th, 2014
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.55 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3.  
  4. class ConsoleTests
  5. {
  6.     static void Main()
  7.     {
  8.         var ticks = Stopwatch.GetTimestamp();
  9.         var uptime = ((double)ticks) / Stopwatch.Frequency;
  10.         var uptimeSpan = TimeSpan.FromSeconds(uptime);
  11.  
  12.         string output = null;
  13.         output = "Last boot: " + uptimeSpan.ToString("%d") + " days, " + uptimeSpan.ToString("%h") +
  14.             " hours, " + uptimeSpan.ToString("%m") + " minutes ago.";
  15.         Console.WriteLine(output);
  16.         Console.WriteLine();
  17.         return;
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment