有个Windows的API可以做到,我现在不记得了,你可以自已查一下。

解决方案 »

  1.   

    SetSystemTime 时要 SYSTEMTIME 每个参数都有值,要不然不成功
      

  2.   

    使用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; 
      

  3.   

      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;
      

  4.   

    不会吧,当年月日确定以后,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
      

  5.   

    procedure TForm1.Button1Click(Sender: TObject);
    var st:TSystemTime;
    begin
      DateTimeToSystemTime(datetimepicker1.DateTime-1/3,st);
      SetSystemTime(st);
    end;
      

  6.   

    啊???难道设置系统时间的时候还要考虑系统的时区设置?这个api难道只以美国时间的为基准?这个时间不是cmos时间?
      

  7.   

    Var ltime,stime : TsystemTime;
    Begin
      //设置事件可用API函数SetLocalTime和SetsystemTime,
      //不过在NT下进程必须有权限SE_SYSTEMTIME_NAME
      //初始化ltime
      ...
      SetLocalTime( ltime ); //与CMOS时间表示一致,一般用此函数  //初始化stime
      ...
      SetSystemTime( ttime ); //是UTC时间,有Time Zone的换算
      ...
    end;