?
Solved

How can I change system Date/time !!

Posted on 1998-10-08
15
Medium Priority
?
200 Views
Last Modified: 2010-04-06
It is very easy question.
What is the Delphi procedures which set date and time ?

Motaz
0
Comment
Question by:Motaz
[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
  • 10
  • 3
  • 2
15 Comments
 
LVL 5

Expert Comment

by:scrapdog
ID: 1342211
Here is the data structure:

TSystemTime = record
    wYear: Word;
    wMonth: Word;
    wDayOfWeek: Word;
    wDay: Word;
    wHour: Word;
    wMinute: Word;
    wSecond: Word;
    wMilliseconds: Word;
  end;


Set the date time like this:

var
  NewTime :TSystemTime;

NewTime.wYear := 1998;   ,etc, etc.

Then you call the function SetSystemTime

SetSystemTime(NewTime);


If you only wanted to change one part of the system time, you could call GetSystemTime

GetSystemTime(NewTime);
NewTime.wYear := 1999;
SetSystemTime(NewTime);


The SetSystemTime function returns a boolean, indicating whether it succeeded or not.  

OK := SetSystemTime(NewTime);
if not OK then ShowMessage('Time not set');




Make sure that Windows is in your uses clause if you use any of these functions.
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1342212
funny - i just added a comment and now this q appears as well as under waiting for answers as under locked...

motaz:

this is as erroneous as inter's comment.
look under your q in "waiting for answer"

the correct API func is SetLocalTime, not SetSystemTime, because the letter would cause any timezone other than GMT +/- 0:00 to add the hours of difference, i.e.

SetSystemTime to 01:00 in Berlin would result in 2:00 on your machine (GMT + 1:00)
SetSystemTime to 01:00 in Moscow would result in 6:00 on your machine (GMT + 3:00)

So use SetLocalTime...

byebye

Black Death.
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1342213
Reject my answer and give Black-Death the points!!
0
Independent Software Vendors: 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!

 
LVL 7

Author Comment

by:Motaz
ID: 1342214
By the way.. I need to know how mush the deference between EDT, PDT compared with GMT, and what did it stand for ( Not GMT ) ?

Motaz
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1342215
aehm - do you mean EST for eastern standard time?
and of course PDT for pacific daylight time?

these parameters can be used in the structure TIME_ZONE_INFORMATION which is used in the API func GetTimeZoneInformation.

Win32.hlp tells me that these parameters are NOT used by the operating system; i.e. SetTimeZoneInformation can set these parameters and GetTimeZoneInformation would return these unchanged - and that the string can as well be empty. I'm not quite sure what this is good for. But i'm on the hunt for more info...

(-.

Black Death.
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1342216
1st research result:

<TimeZones>
UTC:0
GMT:0
AST:4
ADT:3
EST:5
EDT:4
CST:6
CDT:5
MST:7
MDT:6
PST:8
PDT:7

to be continued...

Black Death.
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1342217
i'm just building a little app to get and set the time zones. if you've got a little time to wait, i'll post the source here...

Black Death.
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1342218
i'm just building a little app to get and set the time zones. if you've got a little time to wait, i'll post the source here...

Black Death.
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1342219
this is vresion zeropointone:

have a form, place 1 tmemo, 1tbutton and 1tcombobox on it.
when running this junk, you'll see how to adjust placement best.

unit tzUnit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Registry;

const
  Key_TimeZones = '\SOFTWARE\Microsoft\Windows\CurrentVersion\Time Zones';

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    ComboBox1: TComboBox;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
  private
    { Private-Deklarationen }
    slKeyNames: TStringList;
    TZI: TTimeZoneInformation;
    procedure UpdateDisplay(Display: string);
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.UpdateDisplay(Display: string);
var
  iCnt: Integer;
  Std, Dlt: string;
begin
  with TRegistry.Create do
    try
      RootKey := HKEY_LOCAL_MACHINE;
      if OpenKey(Key_TimeZones, False) then begin
        slKeyNames := TStringList.Create;
        GetKeyNames(slKeyNames);
        for iCnt := 0 to slKeyNames.Count - 1 do with slKeyNames do
          if OpenKey(Key_TimeZones + '\' + Strings[iCnt], False) then begin
            if ReadString('Display') = Display then begin
              ReadBinaryData('TZI', TZI, SizeOf(TTimeZoneInformation));
              GetTimeZoneInformation(TZI);
              Display := ReadString('Display');
              Dlt := ReadString('Dlt');
              Std := ReadString('Std');
              Break;
            end;
          end;
        slKeyNames.Free;
      end;
    finally
      Free;
    end;
  with Memo1 do with TZI do begin
    Clear;
    Lines.Add('Actual Bias: ' + IntToStr(Bias));
    Lines.Add('');
    Lines.Add('StandardName: ' + Std);
    Lines.Add('Standard SystemTime: ');
    with StandardDate do begin
      Lines.Add(' Month: ' + IntToStr(wMonth));
      Lines.Add(' Day  : ' + IntToStr(wDay));
      Lines.Add(' Hour : ' + IntToStr(wHour));
    end;
    Lines.Add('StandardBias: ' + IntToStr(StandardBias));
    Lines.Add('');
    Lines.Add('DaylightName: ' + Dlt);
    Lines.Add('Daylight SystemTime: ');
    with DaylightDate do begin
      Lines.Add(' Month: ' + IntToStr(wMonth));
      Lines.Add(' Day  : ' + IntToStr(wDay));
      Lines.Add(' Hour : ' + IntToStr(wHour));
    end;
    Lines.Add('DaylightBias: ' + IntToStr(DaylightBias));
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Close;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  iCnt: Integer;
begin
  with TRegistry.Create do
    try
      RootKey := HKEY_LOCAL_MACHINE;
      if OpenKey(Key_TimeZones, False) then begin
        slKeyNames := TStringList.Create;
        GetKeyNames(slKeyNames);
        ComboBox1.Sorted := True;
        for iCnt := 0 to slKeyNames.Count - 1 do with slKeyNames do
          if OpenKey(Key_TimeZones + '\' + Strings[iCnt], False) then
            ComboBox1.Items.Add(ReadString('Display'));
        slKeyNames.Free;
      end;
    finally
      Free;
    end;
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
  UpdateDisplay(ComboBox1.Text);
end;

end.



0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1342220
...and for the shortcuts (continued from above):


UTC:0 Coordinated Universal Time

GMT:0 Greenwich Mean Time                (GMT) GMT; Dublin, Edinburg, London

AST:4 Atlantic Standard Time            (GMT-04:00) Atlantic (Kanada)
ADT:3 Atlantic Daylight Time      

EST:5 Eastern Standard Time            (GMT-05:00) Eastern (USA, Kanada)
EDT:4 Eastern Daylight Time

CST:6 Central Standard Time            (GMT-06:00) Central (USA, Kanada)
CDT:5 Central Daylight Time

MST:7 Mountain Standard Time            (GMT-07:00) Mountain (USA, Kanada)
MDT:6 Mountain Daylight Time

PST:8 Pacific Standard Time            (GMT-08:00) Pacific (USA, Kanada); Tijuana
PDT:7 Pacific Daylight Time
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1342221
the values from (GMT) on in every second line is the registrykeyvalue of "Display" which i've used in the above posted source.

any further questions?

rex,

Black Death.
0
 
LVL 7

Author Comment

by:Motaz
ID: 1342222
Thanks very mush BlackDeath.. it is a good work.

You can post any thing as answer and I'll accept.

Motaz.
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1342223
i'm pleased you're pleased.
rex,
Black Death.
0
 
LVL 1

Accepted Solution

by:
BlackDeath earned 40 total points
ID: 1342224
any thing
0
 
LVL 7

Author Comment

by:Motaz
ID: 1342225
Thanks again Black Death.

I'm really like that.

Motaz from Sudan.
motaz1@yahoo.com
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month9 days, 16 hours left to enroll

762 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