获取系统启动后经过的时间

实现效果:

  

知识运用:

  Environment类的TickCount属性  //获取系统启动后经过的毫秒数

  public static int TickCount { get; }

实现代码:

        private void timer1_Tick(object sender, EventArgs e)
        {
            textBox1.Text = GetResult(Environment.TickCount);
        }

        private string GetResult(long l) 
        {
            int s = 0;
            int m = 0;
            int h = 0;
            s = (int)(l / 1000);
            if (s > 60)
            {
                m = s / 60;
                s = s % 60;
            }
            if (m > 60)
            {
                h = m / 60;
                m = m % 60;
            }
            return " "+h + "时" + m+"分" +s+ "秒";
        }

  

猜你喜欢

转载自www.cnblogs.com/feiyucha/p/10293124.html