使用SetSystemTime, var a:_SYStemTIME;//部分参数可忽略,如下 begin a.wYear := 2000; a.wDay := 8; a.wHour := 10; a.wMonth := 6; a.wMinute :=19; a.wMilliseconds := 20; setsystemtime(a); end;_SYStemTIME结构: typedef struct _SYSTEMTIME { WORD wYear; //年 WORD wMonth; //月 WORD wDayOfWeek; //星期 WORD wDay; //日 WORD wHour; //小时 WORD wMinute; //分 WORD wSecond; //秒 WORD wMilliseconds;//毫秒 } SYSTEMTIME;
buf:array[0..255] of char; sString:string; dResult:DWORD; begin With TQuery.Create(frmSetLogin) do begin DataBaseName:=frmMenu.dbHimis.Databasename; SQL.Add('Select GetDate() As Now'); Open; if Abs((FieldByname('Now').AsDateTime-Now))>1/1440.0 then begin if Application.MessageBox('工作站时钟与服务器不一致,要矫正吗?','时钟不一致',MB_OKCANCEL+MB_ICONQUESTION)=ID_OK then begin GetEnvironmentVariable('Comspec',buf,sizeof(buf)); SQL.Clear; SQL.Add('Select Convert(char(20),GetDate(),20) As Now'); Open; sString:='/c Date '+Copy(FieldByName('Now').AsString,1,10); dResult:=ShellExecute(0,'open',buf,Pchar(sString),nil,SW_Hide); sString:='/c Time '+Copy(FieldByName('Now').AsString,12,8); dResult:=ShellExecute(0,'open',buf,Pchar(sString),nil,SW_Hide); if dResult<31 then Showmessage('设置时间错,请检查合法权限'); end; end; end; end;
不会吧,当年月日确定以后,dayofweek已经确定了呀!!! 我这样写 var st: TSystemTime; begin GetSystemTime (st); with st do begin wYear := 2000; wMonth := 1; wDay := 1; wHour := 20; wMinute := 0; wSecond := 0; wMilliseconds := 0; end; SetSystemTime (st); end; 为什么出现的日期是2000-1-2 4:00:00
procedure TForm1.Button1Click(Sender: TObject); var st:TSystemTime; begin DateTimeToSystemTime(datetimepicker1.DateTime-1/3,st); SetSystemTime(st); end;
var
a:_SYStemTIME;//部分参数可忽略,如下
begin
a.wYear := 2000;
a.wDay := 8;
a.wHour := 10;
a.wMonth := 6;
a.wMinute :=19;
a.wMilliseconds := 20;
setsystemtime(a);
end;_SYStemTIME结构:
typedef struct _SYSTEMTIME {
WORD wYear; //年
WORD wMonth; //月
WORD wDayOfWeek; //星期
WORD wDay; //日
WORD wHour; //小时
WORD wMinute; //分
WORD wSecond; //秒
WORD wMilliseconds;//毫秒
} SYSTEMTIME;
sString:string;
dResult:DWORD;
begin
With TQuery.Create(frmSetLogin) do
begin
DataBaseName:=frmMenu.dbHimis.Databasename;
SQL.Add('Select GetDate() As Now');
Open;
if Abs((FieldByname('Now').AsDateTime-Now))>1/1440.0 then
begin
if Application.MessageBox('工作站时钟与服务器不一致,要矫正吗?','时钟不一致',MB_OKCANCEL+MB_ICONQUESTION)=ID_OK then
begin
GetEnvironmentVariable('Comspec',buf,sizeof(buf));
SQL.Clear;
SQL.Add('Select Convert(char(20),GetDate(),20) As Now');
Open;
sString:='/c Date '+Copy(FieldByName('Now').AsString,1,10);
dResult:=ShellExecute(0,'open',buf,Pchar(sString),nil,SW_Hide);
sString:='/c Time '+Copy(FieldByName('Now').AsString,12,8);
dResult:=ShellExecute(0,'open',buf,Pchar(sString),nil,SW_Hide);
if dResult<31 then
Showmessage('设置时间错,请检查合法权限');
end;
end;
end;
end;
我这样写
var st: TSystemTime;
begin
GetSystemTime (st);
with st do
begin
wYear := 2000;
wMonth := 1;
wDay := 1;
wHour := 20;
wMinute := 0;
wSecond := 0;
wMilliseconds := 0;
end;
SetSystemTime (st);
end;
为什么出现的日期是2000-1-2 4:00:00
var st:TSystemTime;
begin
DateTimeToSystemTime(datetimepicker1.DateTime-1/3,st);
SetSystemTime(st);
end;
Begin
//设置事件可用API函数SetLocalTime和SetsystemTime,
//不过在NT下进程必须有权限SE_SYSTEMTIME_NAME
//初始化ltime
...
SetLocalTime( ltime ); //与CMOS时间表示一致,一般用此函数 //初始化stime
...
SetSystemTime( ttime ); //是UTC时间,有Time Zone的换算
...
end;