我也有同样问题,我用 SetSystemTime 都是不一样,总是相差 8 小时。

解决方案 »

  1.   

    系统取的时间是格林威志时间(GMT)
    中国时区(GMT+08:00)与格林威志时间相差8小时 在程序中 +8 即可
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      tSetDate:TDateTime;           
      vDateBias:Variant;
      tTZI:TTimeZoneInformation;
      tST:TSystemTime;
    begin
      gettimezoneinformation(tTZI);
      vDateBias:=tTZI.Bias/1440;
      tSetDate:=strtodatetime(E1.text+'-'+E2.text+'-'+E3.text+' '+
                E4.text+':'+E5.text)+vDateBias;
    //  E1-E2-E3 E4:E5
    //yyyy-mm-dd hh:mm
      with tST do
      begin
        wYear:=StrToInt(FormatDateTime('yyyy',tSetDate));
        wMonth:=StrToInt(FormatDateTime('mm',tSetDate));
        wDay:=StrToInt(FormatDateTime('dd',tSetDate));
        wHour:=StrToInt(FormatDateTime('hh',tSetDate));
        wMinute:=StrtoInt(FormatDateTime('nn',tSetDate));
        wSecond:=0;  
        wMilliseconds:=0;
      end;
      SetsystemTime(tST);
      close;
    end;
      

  3.   

    最简单的方法:
    var 
      sstring:string;
    begin
      sString:='2001-05-21 16:30:49';
      WinExec(pchar('Date '+Copy(sString,1,10)),SW_HIDE);
      WinExec(pchar('Date '+Copy(sString,12,8)),SW_HIDE);
    end;
    //不要笑我傻,这个绝对好用,另外kingsong(牛大锅) 的方法和系统设定是12显示还是24显示有关,不好用
      

  4.   

    SetLocalTime:设置本地时间
    SetSystemTime:设置格林时间