修改系统时间和获取服务器的系统时间(100分)

  • 主题发起人 主题发起人 mingmain
  • 开始时间 开始时间
M

mingmain

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大侠:使用delphi编程如何获取/修改系统时间,如何获取服务器的系统时间.
 
获取服务器上系统文件的修改时间等属性或者取数据库当中的系统表的时间字段都可以
 
似乎有个NMNETTIME(具体名字不是很记得了,在FASTNET里找得到的)组件能获取授时服务器的时间。<br><br>定义一个SystemTime类型的变量t,用GetSystemTime(t)来获取系统时间,<br>SetSystemTime(t)修改<br><br>它包含年、月、日、时、分、秒、毫秒的信息,不过好像是世界时,要自己转到东八区时<br>
 
自己做个时间服务器吧,在delphi的demo中自带的有Indy的例子
 
var vsys : _SYSTEMTIME; <br>&nbsp; &nbsp; vYear, vMonth, vDay, vHour, vMin, vSec, vMm : Word; <br>begin <br>&nbsp; &nbsp;DecodeDate( Trunc(dtpDate.Date), vYear, vMonth, vDay ); <br>&nbsp; &nbsp;DecodeTime( dtpTime.Time, vHour, vMin, vSec, vMm ); <br>&nbsp; &nbsp;vMm := 0; <br>&nbsp; &nbsp;vsys.wYear := vYear; <br>&nbsp; &nbsp;vsys.wMonth := vMonth; <br>&nbsp; &nbsp;vsys.wDay := vDay; <br>&nbsp; &nbsp;vsys.wHour := ( vHour - 2 ); <br>&nbsp; &nbsp;vsys.wMinute := vMin; <br>&nbsp; &nbsp;vsys.wSecond := vSec; <br>&nbsp; &nbsp;vsys.wMilliseconds := vMm; <br>&nbsp; &nbsp;vsys.wDayOfWeek := DayOfWeek( Trunc(dtpDate.Date) ); <br>&nbsp; &nbsp;SetSystemTime( vsys ); <br>end;
 
//修改系统时间<br>SetLocalTime<br>SetSystemTime <br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var MyST:TSystemTime;<br>begin<br>&nbsp; &nbsp;MyST.wYear:=2000;<br>&nbsp; &nbsp;MyST.wMonth:=4;<br>&nbsp; &nbsp;MySt.wDay:=1;<br>&nbsp; &nbsp;MySt.wHour:=17;<br>&nbsp; &nbsp;MySt.wMinute:=20;<br>&nbsp; &nbsp;MySt.wSecond:=20;<br>&nbsp; &nbsp;if SetSystemTime(MyST) then ShowMessage('Change successfully')<br>&nbsp; &nbsp;else ShowMessage('Change failed');<br>end;<br>如果只修改本机时间与服务器同步,那么<br>WinExec(PChar('Net Time //'+ServerName+' /set /y',SW_HIDE);
 
var<br>&nbsp; &nbsp; &nbsp;systemtime : TSystemTime;<br>&nbsp; &nbsp; &nbsp;NewTime:string;<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;ADOQuery1.Close;<br>&nbsp; &nbsp; &nbsp;ADOQUery1.SQL.Clear;<br>&nbsp; &nbsp; &nbsp;ADOQuery1.SQL.Text :='select GetDate()';<br>&nbsp; &nbsp; &nbsp;ADOQuery1.Open;<br>&nbsp; &nbsp; &nbsp;NewTime:=ADOQUery1.Fields[0].AsString;<br>&nbsp; &nbsp; &nbsp;DateTimeToSystemTime(StrToDateTime(NewTime),SystemTime);<br>&nbsp; &nbsp; &nbsp;SetLocalTime(systemtime);<br>&nbsp; &nbsp; &nbsp;end;
 
后退
顶部