怎样和服务器时间统一?想客户端软件是和服务器同步的同时,客户端操作系统的系统时间和服务器没关联当然不是不停的SELECT GETDATE

解决方案 »

  1.   

    iTimeSync 外国软件 很好用 服务器客户端都装上它,客户端可以与服务器同步时间
      

  2.   

    每次启动程序检测,重要时间标志检测,普通sql语句取服务器时间即可
      

  3.   

    在服务器上获取时间datetime,然后:
    sj:_systemtime;
    year,month,day:word;
    hour,min,sec,msec:word;
    decodedate(datetime,year,month,day);
    sj.year:=year;
    ....
    decodetime(datetime,hour,min,sec,msec);
    sj.hour:=hour;
    .....
      

  4.   

    核对后放在什么控件上?timer?他有这个功能吗?
      

  5.   

    //用于获取服务器时间
    //procedure TForm1.Button1Click(Sender: TObject);
    //  DuoServerTime1.InitTime; //启动初始化
    //procedure TForm1.DuoServerTime1InitTime(var ServerTime: TDateTime);
    //  ServerTime:=StrToDateTime('2008-1-1 00:00:00'); //触发初始化服务器端时间的事件
    //procedure TForm1.DuoServerTime1Timer(Sender: TObject);
    //  Caption:=DuoServerTime1.GetDisplayServerTime;  //时时显示
    //  DuoServerTime1.GetServerTime;  //获得服务器端的时间
    unit DuoServerTime;interfaceuses
      Windows, Forms,Messages, SysUtils, Classes,ExtCtrls;type
      TInitTimeNotifyEvent = procedure(var ServerTime:TDateTime) of object;
      TDuoServerTime = class(TTimer)
      private
        FWindowHandle: HWND;
        FLastInitTime:Cardinal;//防止联系操作
        FDelta:Double;//误差
        FServerTime: TDateTime;//服务器第一次收到的时间
        FDisplayFormat: String;
        FOnInitTime: TInitTimeNotifyEvent;
        procedure WndProc(var Msg: TMessage);
      public
        constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;
        procedure InitTime;
        function GetServerTime:TDateTime;
        function GetDisplayServerTime:String;
      published
        property DisplayFormat:String read FDisplayFormat write FDisplayFormat;
        property OnInitTime:TInitTimeNotifyEvent read FOnInitTime write FOnInitTime;
      end;implementation{ TDuoServerTime }constructor TDuoServerTime.Create(AOwner: TComponent);
    begin
      inherited;
      FWindowHandle := Classes.AllocateHWnd(WndProc);
      FLastInitTime:=GetTickCount;
      FDelta:=0;
      FDisplayFormat:='yyyy-mm-dd hh:nn:ss';
    end;destructor TDuoServerTime.Destroy;
    begin
      Classes.DeallocateHWnd(FWindowHandle);
      inherited;
    end;function TDuoServerTime.GetDisplayServerTime: String;
    begin
      Result:=formatdatetime(FDisplayFormat,GetServerTime);
    end;function TDuoServerTime.GetServerTime: TDateTime;
    begin
      Result:=now()-FDelta;
    end;procedure TDuoServerTime.InitTime;
    begin
      if Assigned(OnInitTime) and (GetTickCount-FLastInitTime>=Interval) then
      begin
        FOnInitTime(FServerTime);
        FDelta:=now()-FServerTime;
        FLastInitTime:=GetTickCount;
    //    showmessage('初始化时间');
      end;
    end;procedure TDuoServerTime.WndProc(var Msg: TMessage);
    begin
      with Msg do
        if Msg = WM_TIMECHANGE then
          try
            InitTime;
          except
            Application.HandleException(Self);
          end
        else
          Result := DefWindowProc(FWindowHandle, Msg, wParam, lParam);
    end;end.
      

  6.   

    我写的用于同步服务器时间的控件。
    原理是,JavaScript中的B/S结构显示服务器端的时间。
    你会喜欢的。
    但是我被老板讽刺了一顿。
    还是用Select GetDate() 在需要的时候,比较合群。
      

  7.   

    先Select GetDate()
    然后
    Timer~
      

  8.   

    用WAPi函数WinExe()Command命令提示符下,执行Net Time 
      

  9.   

    1.select getdate,这个要注意gmt与北京时间差8小时.
    2.net time /set命令
    3.自己建立socket同步数据
    至于是否要timer取决于你的实际业务.
      

  10.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        Timer1: TTimer;
        Label1: TLabel;
        procedure Timer1Timer(Sender: TObject);
        procedure FormShow(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      date1:TDateTime ;
    implementationuses DateUtils;{$R *.dfm}procedure TForm1.Timer1Timer(Sender: TObject);
    begin
    date1:=IncSecond(date1,1);
    Label1.Caption:=DateTimeToStr(date1);end;procedure TForm1.FormShow(Sender: TObject);
    begin
    date1:=now;
    end;end.
      

  11.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        Timer1: TTimer;
        Label1: TLabel;
        procedure Timer1Timer(Sender: TObject);
        procedure FormShow(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      date1:TDateTime ;
    implementationuses DateUtils;{$R *.dfm}procedure TForm1.Timer1Timer(Sender: TObject);
    begin
    date1:=IncSecond(date1,1);
    Label1.Caption:=DateTimeToStr(date1);end;procedure TForm1.FormShow(Sender: TObject);
    begin
    date1:=now;
    end;end.
      

  12.   

    那位做同步控件的哥们,其实原理很简单,跟本不用的procedure TForm1.FormShow(Sender: TObject); 
    begin 
    date1:=( 这里用getdate取一下SERVER上的时间); 
    end;