For Programmers: Free Programming Magazines  


Home > Archive > VC Language > May 2006 > Daylight Saving Time









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Daylight Saving Time
William

2006-05-30, 7:15 pm

Env: Windows2000, VC+6.00, Visual Studio 6.0 Service Pack4

I am making an application to show the local time of some cities in the
world. It seems to me Daylight Saving Time doesn't work well on the local
time of London. The code is as follows,

{
//get GMT
SYSTEMTIME sGMT;
GetSystemTime(&sGMT);

//automatically computes whether standard time or daylight savings time
CTime tUTC(sGMT,-1);

//calculate Sydney Time
CTime tSydney = tUTC + CTimeSpan(0,10,0,0);
ShowThisTime(IDC_EDIT1, tSydney);

//calculate Tokyo Time
CTime tTokyo = tUTC + CTimeSpan(0,9,0,0);
ShowThisTime(IDC_EDIT2, tTokyo);

//calculate London Time
CTime tLondon = tUTC + CTimeSpan(0,0,0,0);
ShowThisTime(IDC_EDIT3, tLondon);

//calculate New York Time
CTime tNewYork = tUTC + CTimeSpan(0,-4,0,0);
ShowThisTime(IDC_EDIT4, tNewYork);
}

If I test it at Tokyo at 17:10, the London time is showed at 08:10 while the
correct time should be 09:10.

What's wrong?

Please help.

TIA
William



Igor Tandetnik

2006-05-30, 7:15 pm

William <port@mx15.freecom.ne.jp> wrote:
> I am making an application to show the local time of some cities in
> the world. It seems to me Daylight Saving Time doesn't work well on
> the local time of London. The code is as follows,
>
> {
> //get GMT
> SYSTEMTIME sGMT;
> GetSystemTime(&sGMT);
>
> //automatically computes whether standard time or daylight savings
> time CTime tUTC(sGMT,-1);
>
> //calculate Tokyo Time
> CTime tTokyo = tUTC + CTimeSpan(0,9,0,0);
> ShowThisTime(IDC_EDIT2, tTokyo);
>
> //calculate London Time
> CTime tLondon = tUTC + CTimeSpan(0,0,0,0);
> ShowThisTime(IDC_EDIT3, tLondon);
>
> If I test it at Tokyo at 17:10, the London time is showed at 08:10
> while the correct time should be 09:10.


And what time does it show for Tokyo? Is it correct? Looking at your
code, the times actually shown for London and Tokyo should always be 9
hours apart, independent of any DST rules. They may be wrong at either
or both ends, but they should be 9 hours apart nevertheless. Your code
does simple math on them that does not involve any DST calculations.

Do you want to show current time at a particular location adjusted for
DST in effect _at that location_ ? It is surprisingly difficult. See

http://www.codeproject.com/dotnet/WorldClock.asp

--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com