怎样和服务器时间统一?想客户端软件是和服务器同步的同时,客户端操作系统的系统时间和服务器没关联当然不是不停的SELECT GETDATE
解决方案 »
- access violation at address
- 请大家帮助我,在ADOX中如何在客户端增加存储过程!分数不够再加!
- 第一次使用FASTREPORT,发现程序启动时很慢,不知各位是怎样解决的
- 求delphi5企业版下载。100分了。急呀!!!!!!!!!
- 2002年毕业的兄弟姐妹们,咱们来做做年终总结如何
- 一个关于动态报表的问题
- 一个简单的问题!关于findkey的!
- 我想在做一个系统的时候,其中的一部分功能由DELPHI做,另一部分用VB或VC做,如何进行合并,这样做可行吗
- 怎么用sql语句对日期型字段进行查询啊?
- 动态创建窗口的问题:if not Assigned(form2) then form2:=Tform2.Create(Application);form2.show;错在哪了?第一次创建正常,关掉窗口后再创建就出错。
- delphi 函数体内setlength
- 四则运算遇到的一些问题
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;
.....
//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.
原理是,JavaScript中的B/S结构显示服务器端的时间。
你会喜欢的。
但是我被老板讽刺了一顿。
还是用Select GetDate() 在需要的时候,比较合群。
然后
Timer~
2.net time /set命令
3.自己建立socket同步数据
至于是否要timer取决于你的实际业务.
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.
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.
begin
date1:=( 这里用getdate取一下SERVER上的时间);
end;