工资不涨,物价在疯狂的涨!

博客园 首页 新随笔 联系 订阅 管理
获取计算机从启动到现在总共运行的时间,在asp.net中有现成的类使用(Environment),也可以使用WinAPI
 

    #region 通过Framework类库获取系统启动时间
    private string GetStartTimesByFramework()
    {
        int totalSeconds = Environment.TickCount / 1000;
        int hour = totalSeconds / 3600;
        int minute = totalSeconds % 3600 / 60;
        int second = totalSeconds % 60;
        string startTimes=Convert.ToString(hour + "小时," + minute + "分," + second + "秒.");
        return startTimes;
    }
    #endregion

    #region 通过WinAPI来获取系统启动时间
    [DllImport("kernel32.dll", SetLastError = true)]
    static extern bool GetSystemTimes(out FILETIME lpIdleTime, out FILETIME lpKernelTime, out FILETIME lpUserTime);
    struct FILETIME
    {
        public uint DateTimeLow;
        public uint DateTimeHigh;

    }
    private string GetStartTimesByAPI()
    {
        FILETIME lpIdleTime, lpKernelTime, lpUserTime;
        GetSystemTimes(out   lpIdleTime, out   lpKernelTime, out   lpUserTime);
        ulong lngKernelTime = ((ulong)lpKernelTime.DateTimeHigh << 32) + lpKernelTime.DateTimeLow;
        ulong lngUserTime = ((ulong)lpUserTime.DateTimeHigh << 32) + lpUserTime.DateTimeLow;
        double dRunTime = lngKernelTime + lngUserTime;
        int totalSeconds = Convert.ToInt32(dRunTime / TimeSpan.TicksPerMillisecond / 1000);
        int hour = totalSeconds / 3600;
        int minute = totalSeconds % 3600 / 60;
        int second = totalSeconds % 60;
        string startTimes= Convert.ToString(hour + "小时," + minute + "分," + second + "秒.");
        return startTimes;
    }
    #endregion

posted on 2008-01-30 14:20  腾云驾雾  阅读(409)  评论(0编辑  收藏  举报