#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