Solved

Strange time (hours)

Posted on 2001-07-17
7
194 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
Comment Utility

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
Comment Utility
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
Comment Utility
BTW The source for the UTC is: http://www.dxing.com/utcgmt.htm

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:TomazB
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Well that explains all. Thanks Gemarti.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now