• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

How can I change system Date/time !!

It is very easy question.
What is the Delphi procedures which set date and time ?

Motaz
0
Motaz
Asked:
Motaz
  • 10
  • 3
  • 2
1 Solution
 
scrapdogCommented:
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
 
BlackDeathCommented:
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
 
scrapdogCommented:
Reject my answer and give Black-Death the points!!
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
MotazAuthor Commented:
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
 
BlackDeathCommented:
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
 
BlackDeathCommented:
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
 
BlackDeathCommented:
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
 
BlackDeathCommented:
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
 
BlackDeathCommented:
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
 
BlackDeathCommented:
...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
 
BlackDeathCommented:
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
 
MotazAuthor Commented:
Thanks very mush BlackDeath.. it is a good work.

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

Motaz.
0
 
BlackDeathCommented:
i'm pleased you're pleased.
rex,
Black Death.
0
 
BlackDeathCommented:
any thing
0
 
MotazAuthor Commented:
Thanks again Black Death.

I'm really like that.

Motaz from Sudan.
motaz1@yahoo.com
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 10
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now