Delphi:Unix时间戳转换

时间:2015-08-26 12:45:30

标签: delphi

我正在使用ZK软件机器来设置夏令时和标准时间。在机器中,我将夏令时设置为01.01 00:00(DD.MM HH:MM),标准保存时间设置为31.12 23:59。当我从机器检索信息时,时间格式为Int64:

01.01 00:00 represents '16842752'  
31.12 23:59 represents '203364155'

我无法将日期转换回unix时间戳,我没有获得相同的int64值。

function TMachine.SetDayLightMode(): Boolean;
var
    BeginTime, EndTime : WideString;
    abegin, aend : TDateTime;
begin
    Result := false;
    with MachineDayLight do
    begin
        FCZKEM.GetSysOption(MachineNo, 'DaylightSavingTime', BeginTime); {16842752}
        CZKEM.GetSysOption(MachineNo, 'StandardTime', EndTime); {203364155}

        abegin := StrToDateTime('01.01.1970 00:00:00');
        AEND   := StrToDateTime('31.12.1970 23:59:00');


        BeginTime := IntToStr(DateTimeToUnix(TTimeZone.Local.ToUniversalTime(abegin,false))); //-14400 represents 25.25 19:19
        EndTime   := IntToStr(DateTimeToUnix(TTimeZone.Local.ToUniversalTime(AEND,false))); //31521540 represents 01.22 25:04


        FCZKEM.setSysOption(MachineNo, 'DaylightSavingTime', BeginTime);
        FCZKEM.setSysOption(MachineNo, 'StandardTime', EndTime);


    end;
end;

[EDITED]

是的,根据你的评论,我注意到它不是ZK正在使用的unix时间戳。在线文档没有说明机器返回的时间格式。机器返回以下内容:

  1 min difference has a difference of 1 in its value 
  01.01 00:00 - 16842752 
  01.01 00:01 - 16842753

  1 hour difference gives a difference of 256 
  01.01 00:00 - 16842752 
  01:01 01:00 - 16843008

  1 day difference gives a difference of 65536
  01.01 01:00 - 16843008 
  02.01 01:00 - 16908544 

  1 month difference (31 days) returns 16777216
  01.01. 01:00 - 16843008
  01.02. 01:00 - 33620224

  01.03 01:00  - 50397440
  01.04 01:00  - 67174656

我无法找出机器返回的int64的表示形式。

0 个答案:

没有答案