如题
在先等待

解决方案 »

  1.   

    取远程机器日期时间
    unit Unit3;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TTODInfo = record
        ElapsedTime: Integer; {number of seconds since 00:00:00 January 1, 1970}
        Milliseconds: Integer; {number of milliseconds since last system reset}
        Hours: Integer; {current hour (0-23)}
        Minutes: Integer; {current minute (0-59)}
        Seconds: Integer; {current second (0-59)}
        Hunds: Integer; {current hundredth of a second (0-99)}
        TimeZone: Integer; {time against GMT in minutes}
        {west of Greenwich gives positive, east negative values}
        {value of -1 means undefined time zone}
        Interval: Integer; {clock tick interval in ten-thousandth of a second (0.0001 s)}
        Day: Integer; {day of the month (1-31)}
        Month: Integer; {month of the year (1-12)}
        Year: Integer; {year}
        Weekday: Integer; {day of the week (0-6) 0 = Sunday, 1 = Monday etc.}
      end;
      PTODInfo = ^TTODInfo;type
      TForm1 = class(TForm)
        Button1: TButton;
        Label1: TLabel;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
    const
      netapi32 = 'netapi32.dll';function NetApiBufferFree(Buffer: Pointer): Integer; stdcall;
    function NetRemoteTOD(UNCServerName: PWideChar; Info: Pointer): Integer; stdcall;function ServerTime(const UNCServer: string; var Stamp: TDateTime): Integer;implementation{$R *.dfm}function NetApiBufferFree; external netapi32 name 'NetApiBufferFree';
    function NetRemoteTOD; external netapi32 name 'NetRemoteTOD';function ServerTime(const UNCServer: string; var Stamp: TDateTime): Integer;
    var
      ServerName: PWideChar;
      tod: PTODInfo;
      Year, Month, Day, Hour, Min, Sec, MSec: Word;
    begin
      GetMem(ServerName, (Length(UNCServer) + 1) * SizeOf(WideChar));
      try
        ServerName := StringToWideChar(UNCServer, ServerName, Length(UNCServer) + 1);
        Result := NetRemoteTOD(ServerName, @tod);
        if Result = 0 then
        begin
          try
            Year := tod^.Year;
            Month := tod^.Month;
            Day := tod^.Day;
            Hour := tod^.Hours;
            Min := tod^.Minutes;
            Sec := tod^.Seconds;
            MSec := tod^.Hunds * 10;
            if tod^.TimeZone = -1 then {undefined timezone}
              Stamp := EncodeDate(Year, Month, Day) +
                EncodeTime(Hour, Min, Sec, MSec)
            else
              Stamp := EncodeDate(Year, Month, Day) +
                EncodeTime(Hour, Min, Sec, MSec) - (tod^.TimeZone / 1440);
          finally
            NetApiBufferFree(tod);
          end;
        end;
      finally
        FreeMem(ServerName);
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      t: TDateTime;
    begin
      ServerTime('server', t);
      label1.Caption := DateTimeToStr(t);
    end;end.  t:=GetRemoteDateTime('\\192.168.1.1'); // 主機前要加 \\, 而且要先 trust 過
      showmessage(formatdatetime('yyyy/mm/dd hh:nn:ss',t));
      

  2.   

    为什么一点按钮是1899年的时间呢?
    t:=GetRemoteDateTime('\\192.168.1.1'); 这个放在哪里?
      

  3.   

    输入自己机器的ip就是正确的时间,输入局域网其他机器的时间就是1899年?
    而且要先 trust 過是什么意思?
      
      

  4.   

    用这个
      ServerTime('server', t);
      label1.Caption := DateTimeToStr(t);你可先在dos下c:\>net time //192.168.1.1看看
      

  5.   

    你可先在dos下
    c:\>net time //192.168.1.1
    在dos下运行这个命令,提示192.168.1.1未知
    但是192.168.1.1这个网址可以ping通
      

  6.   

    c:\>net time //192.168.1.1
    这个"//"错了,应该是"\\"