Solved

System Time and date  (Easy)

Posted on 1998-08-08
3
780 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
[X]
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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

690 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