Solved

How can I change system Date/time !!

Posted on 1998-10-08
15
191 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

840 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