Solved

How can I change system Date/time !!

Posted on 1998-10-08
15
189 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Controlled Assessment GCSE - desperate help needed 4 84
Performance of SQL statement 37 111
control image tags in a string ? 12 127
When i run adoquery my application freezes 26 164
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…
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

815 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

11 Experts available now in Live!

Get 1:1 Help Now