Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Strange time (hours)

Posted on 2001-07-17
7
Medium Priority
?
208 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 400 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

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!

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 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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

927 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