在Delphi中怎么设置系统时间?SystemTime能解决吗?好象不能真正的解决问题
请指教如何修改!

解决方案 »

  1.   

    SetSystemTime可以是可以,但它是设置格林威治时间,与北京时间会差8小时
    用SetLocalTime()吧.
      

  2.   

    这个我查过了help说:
    ResWindows NT: The SetLocalTime function fails if the calling process does not have the SE_SYSTEMTIME_NAME privilege. This privilege is disabled by default. Use the AdjustTokenPrivileges function to enable this privilege and again to disable it after the time has been set. For more information about security privileges, see Privileges. SE_SYSTEMTIME_NAME privilege是什么??
    AdjustTokenPrivileges function怎么用,我很@@
    对win2000有用吗?
    请指教!
      

  3.   

    我已经搞定了,谢谢wzrlover(流光逝水) (我怎么给你分^^*)
    下面是我的DD,win sdk的帮助好想有问题!
    function StrToDateTime(const S: string): TDateTime;DescriptionCall StrToDate to parse a string that specifies a date and time value. If S does not contain a valid date, StrToDate raises an EConvertError exception. The S parameter must be in the MM/DD/YY HH:MM:SS format. Specifying AM or PM as part of the time is optional, as are the seconds. Use 24-hour time (7:45 PM is entered as 19:45, for example) if AM or PM is not specified.procedure TForm1.Button1Click(Sender: TObject);
    begin
      edit1.Text:='2002-11-29 18:25:11';
    end;procedure TForm1.Button2Click(Sender: TObject);
    var
      systemtime:Tsystemtime;
      DateTime:TDateTime;
    begin
      DateTime:=StrToDateTime(Edit1.text); //获得时间(TDateTime格式)
      DateTimeToSystemTime(DateTime,systemtime);  //把Delphi的TDateTime格式转化为API的TSystemTime格式
      SetLocalTime(SystemTime);         //设置系统时间
      GetLocalTime(SystemTime);       //读取系统时间
      DateTime:=SystemTimeToDateTime(SystemTime);  //把API的TSystemTime格式 转化为 Delphi的TDateTime格式
      Edit2.Text:=DateTimeToStr(DateTime); //显示当前系统的时间
    end;
    //================================================== 实验
    procedure TForm1.Button3Click(Sender: TObject);
    var
    Mynow:TdateTime;
    begin
     Mynow:=now;
     edit3.Text:=DateTimeToStr(Mynow);
    end;
    //==================================================
      

  4.   

    没什么问题,只是显示格式的问题了
    >>  Edit2.Text:=DateTimeToStr(DateTime); //显示当前系统的时间Edit2.Text:=formatDateTime('yyyy/mm/dd hh:mm:ss',DateTime); //显示当前系统的时间