当用FileAge获取文件整数时间表示后,要用FileDateToDateTime转化为本地时间,FileDateToDateTime是如何实现的呢?换句话说,就是FileAge获取文件整数时间是按什么规则表示的

解决方案 »

  1.   

    是对FileDate进行位操作,参考FileDateToDateTime的代码:
    function FileDateToDateTime(FileDate: Integer): TDateTime;
    {$IFDEF MSWINDOWS}
    begin
      Result :=
        EncodeDate(
          LongRec(FileDate).Hi shr 9 + 1980,
          LongRec(FileDate).Hi shr 5 and 15,
          LongRec(FileDate).Hi and 31) +
        EncodeTime(
          LongRec(FileDate).Lo shr 11,
          LongRec(FileDate).Lo shr 5 and 63,
          LongRec(FileDate).Lo and 31 shl 1, 0);
    end;
      

  2.   

    太感谢2楼的拉,能不能顺便再把 DateTimeToFileDate 的实现也贴出来,然后我就结贴了
      

  3.   

    将光标移到DateTimeToFileDate,按右键选Find Declaration,就可以跳动实现的代码了。function DateTimeToFileDate(DateTime: TDateTime): Integer;
    {$IFDEF MSWINDOWS}
    var
      Year, Month, Day, Hour, Min, Sec, MSec: Word;
    begin
      DecodeDate(DateTime, Year, Month, Day);
      if (Year < 1980) or (Year > 2107) then Result := 0 else
      begin
        DecodeTime(DateTime, Hour, Min, Sec, MSec);
        LongRec(Result).Lo := (Sec shr 1) or (Min shl 5) or (Hour shl 11);
        LongRec(Result).Hi := Day or (Month shl 5) or ((Year - 1980) shl 9);
      end;
    end;