Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

System Time and date  (Easy)

Posted on 1998-08-08
3
777 Views
Last Modified: 2012-05-04
How can i change  system date and time using delphi codes?

Some samples...  Thanks!
0
Comment
Question by:dia050398
  • 2
3 Comments
 
LVL 1

Expert Comment

by:pjdb
ID: 1361734
Assuming you don't care about the milliseconds, drop 6 edit boxes corresponding to years, month, day, hour, minutes and seconds and a button on a form. Put the folowing code in the onclick event of the button

procedure TForm1.Button1Click(Sender: TObject);
Var
 SysTime:TSystemTime;
begin
 FillChar(SysTime, SizeOf(SysTime), #0);      //initialize with 0
 With SysTime Do      //Store the data
 Begin
  SysTime.wYear:=StrToInt(Edit1.Text);
  SysTime.wMonth:=StrToInt(Edit2.Text);
  SysTime.wDay:=StrToInt(Edit3.Text);
  SysTime.wHour:=StrToInt(Edit4.Text);
  SysTime.wMinute:=StrToInt(Edit5.Text);
  SysTime.wSecond:=StrToInt(Edit6.Text);
 End;
 SetSystemTime(SysTime);
end;

NB : you can do exactly the oposite (from the system to your computer by reversing anything and using GetSytemDate instead of SetSytemTime

JDB
0
 

Author Comment

by:dia050398
ID: 1361735
This code can´t establish the TIME, maybe there´ll be another alternative code.
0
 
LVL 1

Accepted Solution

by:
pjdb earned 70 total points
ID: 1361736
Don't work?
I've forgot that it use UTC time...
Use GetLocalTime and SetLocalTime instead to work with your local time.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question