Solved

How can I change system Date/time !!

Posted on 1998-10-08
15
187 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
  • 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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 10 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now