Solved

Set new sysdate from delphi 2.0, 3.0

Posted on 1998-01-14
8
439 Views
Last Modified: 2010-04-04
I need a procedure that can change the system date and time

I use both win95 and NT
0
Comment
Question by:lpd
[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
  • 3
  • 3
  • 2
8 Comments
 
LVL 5

Expert Comment

by:ronit051397
ID: 1356482
Are you using NT or 95?
0
 

Author Comment

by:lpd
ID: 1356483
Edited text of question
0
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 50 total points
ID: 1356484
Use the SetSystemTime api call.

E.g.  To set time to 20 May 1998, 10:30 a.m.

procedure SetNewSystemTime;
var
  SysTime: TSystemTime;
begin
  FillChar(SysTime, SizeOf(TSystemTime), 0);
  SysTime.wYear := 1998;
  SysTime.wMonth := 5;
  SysTime.wDay := 20;
  SysTime.wHour := 8;
  SysTime.wMinute := 30;
  SetSystemTime(SysTime);
end;


Note:  The hour will be 2 more than you specify on Win 95.  (NT???)

JB
0
Technology Partners: 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 5

Expert Comment

by:ronit051397
ID: 1356485
Thank you

it works fine but, a have a small problem with timezones. the procedure that you wrote will set the time as if the timezone was GMT. Do you know how to see that timezone that currently is in use ?

0
 

Author Comment

by:lpd
ID: 1356486
Ah, that would explain why I need to -2 for hour!!

To get current timezone bias, use GetTimeZoneInformation.

E.g.
var
  MinutesDiff: Integer;
  TZInfo: TTimeZoneInformation;
begin
  GetTimeZoneInformation(TZInfo);
  MinutesDiff := TZInfo.Bias;
end;

In my case, MinutesDiff = -120 (i.e. 2 hrs behind).

JB
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1356487
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1356488
P.S.  If you don't want do the TimeZone thing, use SetLocalTime instead of SetSystemTime.

JB
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1356489
Thanks agin
0

Featured Post

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!

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…

710 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