Solved

Strange time (hours)

Posted on 2001-07-17
7
204 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month8 days, left to enroll

617 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