I need to pass "current time as seconds since Jan 1 1970," to match up with an Arduino Time Library.
Is there an existing Function/Procedure available in FPC?
I found this Delphi stuff online, but FPC is stumbling with ULarge and SystemTimeTo...
I tried converting using Lazarus but it made no changes but still will not compile.
The "SystemTimeToFileTime" does not show up with the F1-Help button.
Thoughts and suggestions please?
{code: Delphi}
function AbsNumSecs(ASystemTime: TSystemTime) : Int64;
//returns # of seconds since 00:00:00:000, 01/01/1601
var
lpFileTime: TFileTime;
ULISysTime : ULARGE_INTEGER;
begin
result := -1;
if SystemTimeToFileTime(ASystemTime,lpFileTime) then begin
ULISysTime.LowPart := lpFileTime.dwLowDateTime;
ULISysTime.HighPart := lpFileTime.dwHighDateTime;
//The TFILETIME structure is a 64-bit value representing
//the number of 100-nanosecond intervals since 01/01/1601(UTC)
result := ULISysTime.QuadPart div 10000000;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
lpSystemTime: TSystemTime;
NSecs : Int64;
begin
GetSystemTime(lpSystemTime);
NSecs := AbsNumSecs(lpSystemTime);
if (NSecs <> -1)
then ShowMessage('Seconds since 00:00:00:000 - 01/01/1601:'+
IntToStr(NSecs))
else ShowMessage('Error in AbsNumSecs!'+#13+
SysErrorMessage(GetLastError));
end;
{code: Delphi}