用服务器 SQL
SELECT @nowdate=getdate()

解决方案 »

  1.   

    执行一个SQL:select getdate()
      

  2.   

    用存储过程
    CREATE PROCEDURE returntime 
    @dd datetime output
    AS
    select @dd=getdate()
    (sql 7)
      

  3.   

    ADOQuery1...
    adoquery1.sql.add('select getdate() as mydate');
    adoquery1.open;
    showmessage(formatdatetime('hh:mm:ss',adoquery1.fieldbyname('mydate').asdatetime));
      

  4.   

    {-------------------------------------------------------------------
      功能:  设置当前机器的系统时间为服务器的时间
      参数:  ServerNmae:WideString;
                        服务器的名字
      返回值: 指定服务器的时间
      作者:   zsy_good
      时间:   2002-6-27
    -------------------------------------------------------------------}
    type       //记录时间的结构
      PTime_Of_Day_Info = ^TTime_Of_Day_Info;
      TTime_Of_Day_Info = record
        tod_elapsedt  :Integer;
        tod_msecs     :Integer;
        tod_hours     :Integer;
        tod_mins      :Integer;
        tod_secs      :Integer;
        tod_hunds     :Integer;
        tod_timezone  :LongInt;
        tod_tinterval :Integer;
        tod_day       :Integer;
        tod_month     :Integer;
        tod_year      :Integer;
        tod_weekday   :Integer;
      end;         function NetRemoteTOD(ServerName :PWideChar;var buffer :pointer) :Integer; stdcall; external 'netapi32.dll';
    function NetApiBufferFree(buffer : Pointer) :Integer; stdcall; external 'netapi32.dll';function Tf_Main._SetRemoteDateTime(ServerName: WideString): TDatetime;
    var
        Buffer     :Pointer;
        Rek        : PTime_Of_Day_Info;
        ADate      ,
        ATime      :TDatetime;
        td:_Systemtime;
    begin
      if NetRemoteTOD(PWideChar(ServerName),Buffer) <>0 then
      begin
        application.MessageBox('校对服务器时间失败,请和管理员联系!','错误',0);
        exit;
      end;
      Rek:=PTime_Of_Day_Info(Buffer);
      td.wYear:=rek.tod_year;
      td.wMonth:=rek.tod_month ;
      td.wDay:=rek.tod_day;
      td.wHour:=rek.tod_hours;
      td.wMinute :=rek.tod_mins;
      td.wSecond :=rek.tod_secs;
      td.wMilliseconds :=rek.tod_hunds ;
      setsystemtime(td);         //设置服务器时间
      NetApiBufferFree(Buffer);  //释放资源
    end;