Declare Function SetSystemTime Lib "kernel32" Alias "SetSystemTime" (lpSystemTime As SYSTEMTIME) As Long 说明 设置当前系统时间 返回值 Long,非零表示成功,零表示失败。会设置GetLastError 参数表 参数 类型及说明 lpSystemTime SYSTEMTIME,这个结构指定了新的地方时间。其中的wDayOfWeek条目会被忽略
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
从SERVER端控制,用户登陆时执行net time也是一种办法
不知道你的服务器是指哪里的服务器!!!本地服务器可以这样! C:\>net time \\ComputerName /SET /Y
说明
设置当前系统时间
返回值
Long,非零表示成功,零表示失败。会设置GetLastError
参数表
参数 类型及说明
lpSystemTime SYSTEMTIME,这个结构指定了新的地方时间。其中的wDayOfWeek条目会被忽略
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
C:\>net time \\ComputerName /SET /Y