Solved

Strange time (hours)

Posted on 2001-07-17
7
198 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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 …

821 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