var t:integer;
sTime: TSystemTime;
_ms,_s,_m,_h:integer;
begin
GetLocalTime(sTime);
t:=GetTickCount();
t:=sTime.wSecond *1000+sTime.wMilliseconds +sTime.wMinute *60000+sTime.wHour*3600000-t;
_ms:=t mod 1000;//得到微秒
t:=(t-_ms) div 1000;
_s:=t mod 60;//得到秒
t:=(t-_s) div 60;
_m:=t mod 60;//得到分
t:=(t-_m) div 60;
_h:=t mod 60;//得到小时
ShowMessage(Format('开机时间:%d:%d:%d.%d',[_h,_m,_s,_ms]));
end;
系统安装时间
function DateInstallWindows (var DateInstall: TDateTime):Boolean;
var
RegDate: TRegistry;
Buffer: Integer;
begin
Result:=False;
RegDate := TRegistry.Create;
try
RegDate.RootKey := HKEY_LOCAL_MACHINE;
if Win32Platform = VER_PLATFORM_WIN32_NT Then
Begin
if RegDate.OpenKey('Software\Microsoft\Windows NT\CurrentVersion', True)
then
Begin
RegDate.ReadBinaryData('InstallDate',Buffer, sizeof (Buffer));
DateInstall:=StrToDateTime (FormatDateTime('dd/mm/yyyy hh:nn', FileDateToDateTime(Buffer)));
Result:=True;
end
end
else
if RegDate.OpenKey('Software\Microsoft\Windows\CurrentVersion', True)
then
Begin
RegDate.ReadBinaryData('FirstInstallDateTime',Buffer, sizeof (Buffer));
DateInstall:=StrToDateTime (FormatDateTime('dd/mm/yyyy hh:nn', FileDateToDateTime(Buffer)));
Result:=True;
end
finally
RegDate.CloseKey;
RegDate.Free;
end;
end;
2.用法
procedure TForm1.BitBtn2Click(Sender: TObject);
var
TheDate: TDateTime;
begin
if DateInstallWindows (TheDate) Then Label1.Caption:=DateTimeToStr (TheDate);
end;