.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> DateTime >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Get SystemUpTime

Posted By:Ravi Ranjan Kumar       Posted Date: June 09, 2011    Points: 40    Category: DateTime    URL: http://www.dotnetspark.com  

This Code will enable you to get SystemUpTime with formated values
 

To get SystemUpTime in C# we can use given function, it will responsible to return SystemUpTime with Formated string,

public string getSystemUpTime()
        {
            TimeSpan ts;
            ts = TimeSpan.FromMilliseconds(Environment.TickCount);
            string str = string.Format("{0}d {1}h {2}m {3}s", ts.Days, ts.Hours, ts.Minutes, ts.Seconds);
            return str;
        }
How to Use 

suppose we want to get SystemUpTime on click event of a button then we will write code in given way

 private void button1_Click(object sender, EventArgs e)
        {
           label1.Text = getSystemUpTime(); // Gives SystemUpTime
        }


     

Further Readings:

    Responses

    No response found. Be the first to respond this post

    Post Comment

    You must Sign In To post reply
    Find More code samples in C#, ASP.Net, Vb.Net and more Here

    Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend