RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
SysUtils.SystemTimeToDateTime Function

Converts a system time value into a TDateTime value.

Pascal
function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;
C++
TDateTime SystemTimeToDateTime(const TSystemTime SystemTime);

Call SystemTimeToDateTime to convert a value from Windows 32's TSystemTime (Delphi) or _SYSTEMTIME (C++) API format to a TDateTime value. SystemTimeToDateTime is available on Windows only.  

C++ Examples: 

 

/*
The following code retrieves the current date and time using
the Windows GetLocalTime API call, and converts this value
to a TDateTime value.
*/
TDateTime __fastcall GetCurrentDateTime()
{
  SYSTEMTIME SystemTime;
  GetLocalTime(&SystemTime);
  return SystemTimeToDateTime(SystemTime);
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Label1->Caption = DateTimeToStr(GetCurrentDateTime());
}

 

Delphi Examples: 

{
The following code retrieves the current date and time using
the Windows GetLocalTime API call, and converts this value
to a TDateTime value.
}
function GetCurrentDateTime: TDateTime;
var
  SystemTime: TSystemTime;
begin
  GetLocalTime(SystemTime);
  Result := SysUtils.SystemTimeToDateTime(SystemTime);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Label1.Caption := SysUtils.DateTimeToStr(GetCurrentDateTime);
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!