想在程序中动态修改windows系统时间
怎么做呢?急!!!

解决方案 »

  1.   

    var
      Y, M, D, H, N, S, MS: Word;
      T: TDateTime;
      SystemTime: TSystemTime;
    begin
      Y := 2005;
      M := 3;
      D := 10;
      H := 1;
      N := 0;
      S := 0;
      MS := 0;
      T := EncodeDateTime(Y, M, D, H, N, S, MS);  // 2005-3-10 1:0:0.0
      DateTimeToSystemTime(T, SystemTime);
      SetLocalTime(SystemTime);
    end;要 uses DateUtils;
      

  2.   

    var systemtime:Tsystemtime;
       DateTime:TDateTime;
    begin
      DateTime:=StrToDateTime(Edit1.text);
      DateTimeToSystemTime(DateTime,systemtime);
      SetLocalTime(SystemTime);
      GetLocalTime(SystemTime);
      DateTime:=SystemTimeToDateTime(SystemTime);
    end;
      

  3.   

    不行啊 在window2000下可以 在xp中说我的datetime格式不对  为什么啊
      

  4.   

    不会吧,xp用的时间格式和window2000不同吗?
      

  5.   

    我这里有一个设置系统时间格式的代码:
    procedure TfrmMain.SetTimeFormat;//设置系统时间格式
    var
      Locale: LCID;
    begin
      Locale := GetThreadLocale;
      // 设置短日期格式
      if not SetLocaleInfo(Locale, LOCALE_SSHORTDATE, PChar('yyyy-MM-dd')) then
      begin
        Application.MessageBox('设置系统时间格式错误', '错误', mb_OK + mb_IconError);
        Beep;
      end;
      // 设置长日期格式,分隔符对长日期格式无效
      if not SetLocaleInfo(Locale, LOCALE_SLONGDATE, PChar('yyyy''-''MM''-''dd')) then
      begin
        Application.MessageBox('设置系统日期格式错误', '错误', mb_OK + mb_IconError);
        Beep;
      end;
      // 设置时间格式(Windows中没有长短之分)
      if not SetLocaleInfo(Locale, LOCALE_STIMEFORMAT, PChar('HH:mm:ss')) then
      begin
        Application.MessageBox('设置时间格式错误', '错误', mb_OK + mb_IconError);
        Beep;
      end;
      // 将改变通知其他应用程序
      SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, 0);
    end;
      

  6.   

    The SetSystemTime function sets the current system time and date. The system time is expressed in Coordinated Universal Time (UTC). BOOL SetSystemTime(    CONST SYSTEMTIME *lpSystemTime  // address of system time to set 
       );
     ParameterslpSystemTimePoints to a SYSTEMTIME structure that contains the current system date and time. 
    The wDayOfWeek member of the SYSTEMTIME structure is ignored.  Return ValuesIf the function succeeds, the return value is nonzero.
    If the function fails, the return value is zero. To get extended error information, call GetLastError. ResWindows NT: The SetSystemTime 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. 
    Windows 95: Security privileges are not supported or required.
      

  7.   

    The SYSTEMTIME structure represents a date and time using individual members for the month, day, year, weekday, hour, minute, second, and millisecond. typedef struct _SYSTEMTIME {  // st  
        WORD wYear; 
        WORD wMonth; 
        WORD wDayOfWeek; 
        WORD wDay; 
        WORD wHour; 
        WORD wMinute; 
        WORD wSecond; 
        WORD wMilliseconds; 
    } SYSTEMTIME; 
     MemberswYearSpecifies the current year. wMonthSpecifies the current month; January = 1, February = 2, and so on. wDayOfWeekSpecifies the current day of the week; Sunday = 0, Monday = 1, and so on. wDaySpecifies the current day of the month. wHourSpecifies the current hour. wMinuteSpecifies the current minute. wSecondSpecifies the current second. wMillisecondsSpecifies the current millisecond.  ResIt is not recommended that you add and subtract values from the SYSTEMTIME structure to obtain relative times. Instead, you should · Convert the SYSTEMTIME structure to a FILETIME structure.
    · Copy the resulting FILETIME structure to a LARGE_INTEGER structure.
    · Use normal 64-bit arithmetic on the LARGE_INTEGER value.