Solved

Strange time (hours)

Posted on 2001-07-17
7
202 Views
Last Modified: 2010-04-06
I am trying to set system time trough my program but there is diference bettween hours in SisTime and time I get from function Time. The diference is two hours.  

var
TempTime:TDateTime;
SisTime:_SYSTEMTIME;

TempTime:=time;
GetSystemTime(SisTime);
DecodeTime(TempTime,SisTime.wHour,SisTime.wMinute,SisTime.wSecond,SisTime.wMilliseconds);

{if here SisTime.wHour is 20 system watch shows 22}

WHY??? What am I doing wrong?

If I use <SetSystemTime(SisTime)> and I set SisTime.wHour to 18, system watch will show 20 but minutes and other values are OK.
0
Comment
Question by:TomazB
[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
7 Comments
 
LVL 3

Expert Comment

by:nnbbb09
ID: 6291235

Very strange. When I user your code the result was one hour behind. Have you tried using GetLocalTime and SetLocalTime. The results seem to be ok ie : they're the same as the tray clock.

Jo
0
 
LVL 21

Accepted Solution

by:
gemarti earned 100 total points
ID: 6291455
The GetSystemTime() function is coordinated in the Universal Time Code, so...To convert UTC to local time, you have to add or subtract hours from it. For persons west of the zero meridian to the international date line (which includes all of North America), hours are subtracted from UTC to convert to local time. Below is a table showing the number of hours to subtract from local time zones in North America in order to convert UTC to local time:
Local Time Subtract from UTC:
Atlantic Standard Four hours
Atlantic Daylight Three hours
Eastern Standard Five hours
Eastern Daylight Four hours
Central Standard Six hours
Central Daylight Five hours
Mountain Standard Seven hours
Mountain Daylight Six hours
Pacific Standard Eight hours
Pacific Daylight Seven hours
Alaskan Standard Nine hours
Alaskan Daylight Eight hours
Hawaiian Standard Ten hours


0
 
LVL 21

Expert Comment

by:gemarti
ID: 6291459
BTW The source for the UTC is: http://www.dxing.com/utcgmt.htm

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

 

Author Comment

by:TomazB
ID: 6291462
Yes, I know Get and SetLocalTime and they are OK but....
what is the reason for that strange behaviour of SystemTime? Don't tell me that this is NT bug.....
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6291771
It's not strange behaviour.  It's what gemarti said.  The SYSTEMTIME is set to GMT and therefore, you need to calculate your local time by subtracting or adding your time zone to the SYSTEMTIME.  For instance, I'm in Sydney Australia, so I need to add 10 hours to get my correct time.

From the help file...

It is not recommended that you add and subtract values from the SYSTEMTIME structure to obtain relative times. Instead, you should

?     Convert the SYSTEMTIME structure to a FILETIME structure.
?     Copy the resulting FILETIME structure to a LARGE_INTEGER structure.
?     Use normal 64-bit arithmetic on the LARGE_INTEGER value.


Cheers,

Stu.
0
 
LVL 17

Expert Comment

by:geobul
ID: 6292767
Hi,
You can use SetLocalTime API for that purpose. In this case the parameter is the local time you want to set.

Regards, Geo
0
 

Author Comment

by:TomazB
ID: 6292941
Well that explains all. Thanks Gemarti.
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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

739 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