[BLUE]
获取时间:
var
ServerDateTime:TDateTime;
begin
Query1.Active:=False;
Query1.SQL.Clear;
Query1.SQL.Add('SELECT GETDATE() AS TheDateTime');
Query1.Active:=True;
ServerDateTime:=Query1.FieldByName('TheDateTime').AsDateTime;
end;
[/BLUE][GREEN]
设置客户系统时间:
if SetPCSystemTime(ServerDateTime) then
MessageBox(Handle,'系统时间设置成功!','提示框',MB_OK+MB_ICONINFORMATION);
function SetPCSystemTime(tDati: TDateTime): Boolean;
var
tSetDati: TDateTime;
vDatiBias: Variant;
tTZI: TTimeZoneInformation;
tST: TSystemTime;begin
GetTimeZoneInformation(tTZI);
vDatiBias := tTZI.Bias / 1440;
tSetDati := tDati + vDatiBias;
with tST do
begin
wYear := StrToInt(FormatDateTime('yyyy', tSetDati));
wMonth := StrToInt(FormatDateTime('mm', tSetDati));
wDay := StrToInt(FormatDateTime('dd', tSetDati));
wHour := StrToInt(FormatDateTime('hh', tSetDati));
wMinute := StrToInt(FormatDateTime('nn', tSetDati));
wSecond := StrToInt(FormatDateTime('ss', tSetDati));
wMilliseconds := 0;
end;
SetPCSystemTime := SetSystemTime(tST);
end;
[/GREEN]