Articles   Members Online: 3
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to change system date and time in Windows Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
10-Oct-02
Category
System
Language
Delphi 2.x
Views
98
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas 

I want to assign a new time to the system time. How would I do this? I tried to get 
the system time through GetSystemTime() and set the new time to SetSystemTime(), 
but I get the wrong results.

Answer:

Solve 1:

This sets the time to the same time in year 1999:
1   
2   procedure TForm1.Set1999(Sender: TObject);
3   var
4     stSystemTime: TSystemTime;
5   begin
6     Windows.GetLocalTime(stSystemTime);
7     stSystemTime.wYear := 1999;
8     Windows.SetLocalTime(stSystemTime);
9   end;



Solve 2:

By using the following call (example is a method of a button click) you may 
directly modify the date and time of Windows. 
10  
11  procedure TForm1.Button1Click(Sender: TObject);
12  var
13    NewTime: TSystemTime;
14  begin
15    FillChar(NewTime, sizeof(NewTime), #0);
16    NewTime.wYear := 2000;
17    NewTime.wMonth := 8;
18    NewTime.wDay := 28;
19    NewTime.wHour := 0;
20    NewTime.wMinute := 0;
21    NewTime.wSecond := 0;
22    NewTime.wMilliseconds := 0;
23  
24    SetLocalTime(NewTime);
25  end;


Please note that when you do chage the system time, send a WM_TIMECHANGE message to 
all toplevel windows so that they can detect the time change...  You should do this 
for all version of windows but 2000 since it does it by its self.  Bellow is the 
code: 
26  
27  if IsWin2000 = False then
28    SendMessage(HWND_TOPMOST, WM_TIMECHANGE, 0, 0);
29  
30  function IsWin2000(): Boolean;
31  var
32    OSInfo: TOSVersionInfo;
33  begin
34    Result := False;
35    OSInfo.dwOSVersionInfoSize := SizeOf(OsInfo);
36    if not GetVersionEx(OSInfo) then
37    begin
38      Exit;
39    end;
40    if OsInfo.dwPlatformID = VER_PLATFORM_WIN32_NT then
41    begin
42      if OSInfo.dwMajorVersion >= 5 then
43        Result := True;
44    end;
45  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC