Delphi 2009中的系统正常运行时间 [英] System Uptime in Delphi 2009

查看:115
本文介绍了Delphi 2009中的系统正常运行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编码以查看计算机已开启多长时间。

How can I code to see how long the computer has been on.

如果可能的话,提供简单的代码示例。

Simple examples of code if possible.

推荐答案

您使用<一个href = http://msdn.microsoft.com/zh-cn/library/ms724408%28VS.85%29.aspx rel = nofollow noreferrer> GetTickCount 函数参见此示例。

You use GetTickCount function see this example.

program Ticks;

{$APPTYPE CONSOLE}

uses
  Windows,
  SysUtils;

function TicksToStr(Ticks: Cardinal): string;    //Convert Ticks to String
var
  aDatetime : TDateTime;
begin
   aDatetime := Ticks  / SecsPerDay / MSecsPerSec;
   Result := Format('%d days, %s', [Trunc(aDatetime), FormatDateTime('hh:nn:ss.z', Frac(aDatetime))]) ;
end;

begin
  try
     Writeln('Time Windows was started '+ TicksToStr(GetTickCount));
     Readln;
  except
    on E:Exception do
      Writeln(E.Classname, ': ', E.Message);
  end;
end.

更新

要获取其他格式的信息,只需编辑此行,

to get the info in other format just must edit this line,

   Result := Format('%d days, %d hours %d minutes %d seconds ', [Trunc(aDatetime), HourOf(aDatetime),MinuteOf(aDatetime),SecondOf(aDatetime) ]) ;

并添加单位DateUtils。

and add the unit DateUtils.

这篇关于Delphi 2009中的系统正常运行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆