var<br> hh,mm,ss,ms:word;<br>begin<br> DecodeTime(DateTime,hh,mm,ss,ms);<br> hx:=hh;<br> mx:=mm;<br> sx:=ss;<br>end;<br>设置系统时间 change the system time?<br><br>{1.} <br><br>{ <br> For Windows 9X/ME/NT/2000/XP: <br><br> The SetLocalTime function fails if the calling process does not have <br> the SE_SYSTEMTIME_NAME privilege. This privilege is disabled by default. <br> Use the AdjustTokenPrivileges function to enable this privilege. <br>} <br><br>function SetPCSystemTime(dDateTime: TDateTime): Boolean; <br>const <br> SE_SYSTEMTIME_NAME = 'SeSystemtimePrivilege'; <br>var <br> hToken: THandle; <br> ReturnLength: DWORD; <br> tkp, PrevTokenPriv: TTokenPrivileges; <br> luid: TLargeInteger; <br> dSysTime: TSystemTime; <br>begin <br> Result := False; <br> if (Win32Platform = VER_PLATFORM_WIN32_NT) then <br> begin <br> if OpenProcessToken(GetCurrentProcess, <br> TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then <br> begin <br> try <br> if not LookupPrivilegeValue(nil, SE_SYSTEMTIME_NAME, luid) then Exit; <br> tkp.PrivilegeCount := 1; <br> tkp.Privileges[0].luid := luid; <br> tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED; <br> if not AdjustTokenPrivileges(hToken, False, tkp, SizeOf(TTOKENPRIVILEGES), <br> PrevTokenPriv, ReturnLength) then <br> Exit; <br> if (GetLastError <> ERROR_SUCCESS) then <br> begin <br> raise Exception.Create(SysErrorMessage(GetLastError)); <br> Exit; <br> end; <br> finally <br> CloseHandle(hToken); <br> end; <br> end; <br> end; <br> DateTimeToSystemTime(dDateTime, dSysTime); <br> Result := Windows.SetLocalTime(dSysTime); <br>end; <br><br>{************************************************************} <br><br>{2.} <br><br>procedure TForm1.Button1Click(Sender: TObject); <br>var <br> SystemTime: TSystemTime; <br> NewTime, NewDate: string; <br>begin <br> NewTime := '13:58:00'; <br> NewDate := '02.02.2001'; // or '02/02/01' <br> DateTimeToSystemTime(StrToDate(NewDate) + StrToTime(NewTime), SystemTime); <br> SetLocalTime(SystemTime); <br> // Tell windows, that the Time changed! <br> PostMessage(HWND_BROADCAST, WM_TIMECHANGE, 0, 0); // * <br>end; <br><br>{ <br> Windows 2000 and later: An application should not broadcast <br> the WM_TIMECHANGE message because the system will broadcast <br> this message when the application changes the system time. <br>} <br><br>{************************************************************} <br><br>{3.} <br><br>function SetSystemTime(DateTime: TDateTime): Boolean; <br>{ (c) by UNDO } <br>var <br> tSetDati: TDateTime; <br> vDatiBias: Variant; <br> tTZI: TTimeZoneInformation; <br> tST: TSystemTime; <br>begin <br> GetTimeZoneInformation(tTZI); <br> vDatiBias := tTZI.Bias / 1440; <br> tSetDati := DateTime + vDatiBias; <br> with tST do <br> begin <br> wYear := StrToInt(FormatDateTime('yyyy', tSetDati)); <br> wMonth := StrToInt(FormatDateTime('mm', tSetDati)); <br> wDay := StrToInt(FormatDateTime('dd', tSetDati)); <br> wHour := StrToInt(FormatDateTime('hh', tSetDati)); <br> wMinute := StrToInt(FormatDateTime('nn', tSetDati)); <br> wSecond := StrToInt(FormatDateTime('ss', tSetDati)); <br> wMilliseconds := 0; <br> end; <br> Result := Windows.SetSystemTime(tST); <br>end; <br><br>这些资料,你看看吧<br>