关于从服务器读取时间更新客户端系统时间的问题,我想用NMDayTime控件得到了时间,《问题是我如何该系统时间?〉,没做过,请指教。

解决方案 »

  1.   

    Declare Function SetSystemTime Lib "kernel32" Alias "SetSystemTime" (lpSystemTime As SYSTEMTIME) As Long 
    说明 
    设置当前系统时间 
    返回值 
    Long,非零表示成功,零表示失败。会设置GetLastError 
    参数表 
    参数 类型及说明 
    lpSystemTime SYSTEMTIME,这个结构指定了新的地方时间。其中的wDayOfWeek条目会被忽略 
      

  2.   

    procedure TForm1.Button1Click(Sender: Tobject);
    var
      CurrentTime: TSystemTime;        // holds the system time
    begin
      {retrieve the system time}
      GetSystemTime(CurrentTime);  {display the system time}
      Edit1.Text := IntToStr(CurrentTime.wmonth)+'/'+
                    IntToStr(CurrentTime.wDay)+'/'+
                    IntToStr(CurrentTime.wYear);
      Edit2.Text := IntToStr(CurrentTime.wDayOfWeek)+' Day of week';  Edit3.Text := IntToStr(CurrentTime.whour)+':'+
                    IntToStr(CurrentTime.wMinute)+':'+IntToStr(CurrentTime.wSecond);
    end;procedure TForm1.Button2Click(Sender: TObject);
    var
      CurrentTime : TSystemTime;       // holds the system time
    begin
      {retrieve the system time to initialize members of CurrentTime
       that are not supplied by the user}
      GetSystemTime(CurrentTime);
      try    {set the date from the supplied date}
        DecodeDate(StrToDateTime(Edit1.Text),CurrentTime.wYear,CurrentTime.wMonth,
          CurrentTime.wDay);    {set the time from the supplied time}
        DecodeTime(StrToTime(Edit3.Text),CurrentTime.wHour,CurrentTime.wMinute,
          CurrentTime.wSecond,CurrentTime.wMilliseconds);    {set the system time}
        SetSystemTime(CurrentTime)
      except
        {indicate if there was an error}    on E:Exception do ShowMessage('Error setting system time');
      end;
    end;The Tomes of Delphi 3: Win32 Core API Help File by Larry Diehl
      

  3.   

    从SERVER端控制,用户登陆时执行net time也是一种办法
      

  4.   

    不知道你的服务器是指哪里的服务器!!!本地服务器可以这样!
    C:\>net time \\ComputerName /SET /Y