Change Windows Date from Delphi

How can I change Windows system date from a Delphi application?
Joern
rainbowsoftwareAsked:
Who is Participating?
 
rene100Connect With a Mentor Commented:
Hi

use the SetSystemTime function.

regards
rene

0
 
rainbowsoftwareAuthor Commented:
I'm rather confused, could you please give me a hint?
Joern
0
 
rene100Commented:
I'm sorry, the SetLocalTime funtion is bettter, because you don't have to care about time zones etc.
example:

procedure TForm1.Button1Click(Sender: TObject);
var
sys: tsystemtime;
begin
sys.wSecond:=1;
sys.wDay:=1;
sys.wHour:=7;
sys.wDayOfWeek:=3; //ignored
sys.wMilliseconds:=5;
sys.wMinute:=30;
sys.wMonth:=5;
sys.wYear:=2001;
if SetLocalTime(sys)=true then
   showmessage('Time changed!');
end;

this sets the system-time to 1.5.2001 7:30:01

regards
rene
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
rainbowsoftwareAuthor Commented:
Thanks to Rene for a perfect solution.
Maybe you could tell me, if there is a simple way to change the system date format from dd-MM-yy to dd-MM-yyyy from within a Delphi application.
Joern
0
 
rene100Commented:
This should work:

if SetLocaleInfo(LOCALE_system_DEFAULT,LOCALE_SLONGDATE,pchar('dd.MM.yyyy ')) then
   showmessage('Dateformat changed!');
Ig you want to change teh shortdate-format, use LOCALE_SSHORTDATE instead of _SLONGDATE.
Be aware that the new date is case sensitive: 'DD.mm.YYYY' will not work.

regards
rene
0
 
rainbowsoftwareAuthor Commented:
thanks a lot, just what I needed.
Joern
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.