Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

C# Program to Get the Number of Milliseconds Elapsed Since System Started Using Environment Class

  • Last Updated : 24 Oct, 2021

In C#, Environment Class provides information about the current platform and manipulates, the current platform. It is useful for getting and setting various operating system-related information. We can use it in such a way that it retrieves command-line arguments information, exit codes information, environment variable settings information, contents of the call stack information, and time since the last system boot in milliseconds information. By just using some predefined methods we can get the information of the Operating System using the Environment class. Here In this article, we will get the number of milliseconds so we use the TickCount Property of the Environment class. TickCount property is used to get the number of milliseconds of the environment class from the starting. It will return the seconds in an integer format

Syntax:

int Environment.TickCount

Return Type: Returns number of elapsed seconds which is an integer

Example 1:



C#




// C# program to evaluate the sum and then find the time
// that elapsed since system started
using System;
  
class GFG{
      
static public void Main()
{
      
    // Evaluate the expression
    int summ = 2 + 3;
    Console.WriteLine("Sum is: " + summ);
      
    // Count the elapsed seconds
    Console.WriteLine("So, the tick count is : "
                      Environment.TickCount);
}
}

Output:

Sum is: 5
So, the tick count is : 12173138

Example 2: 

C#




// C# program to find the time with out 
// any delay (With out no operation)
using System;
  
class GFG{
      
static public void Main()
{
      
    // Count the elapsed seconds
    Console.WriteLine("The tick count is : "
                      Environment.TickCount);
}
}

Output:

The tick count is : 11475417



My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!