The application I develop is used worldwide so I can not
assume or hardcode anything. This should not
be a problem since winapi have functions to handle this.
I do the following.
The function I use to convert UTC time to local time (New
York time for me) looks like this:
COleDateTime ConvertToLocalTime(const COleDateTime&
timeUTC)
{
// Set time environment variables.
_tzset();
// Output environment variables
CString str;
str.Format("offset = %d, daylight = %d, %s, %s\n",
_timezone, _daylight, _tzname[0], _tzname[1]);
cout << (LPCTSTR)str<< endl;
// Adjust given time to local time.
COleDateTimeSpan timeSpanOffset(0, 0, 0, _timezone);
COleDateTime timeLocal = timeUTC - timeSpanOffset;
// Output local time
str.Format("time UTC = %s, time local = %s",
timeUTC.Format("%H:%M:%S"), timeLocal.Format("%H:%M:%S"));
cout << (LPCTSTR)str<< endl;
return timeLocal;
}
and produces the following output:
offset = 18000, daylight = 1, Eastern Standard Time,
Eastern Daylight Time
time UTC = 11:23:45, time local = 06:23:45
Five hour difference which is fine during winter time,
but when daylight saving is in effect, it only differs
four hours. Windows apperently handles this fine, the
clock in the notification area adjusts properly, but is
there some way from the API to find out if daylight
saving is in effect or not? Are there other ways than
using
the functions I been using? _daylight only tells you if
Windows should adjust for daylight saving or not.
Disabling automatic adjust of daylight saving in the
Windows clock only affects the output as follows:
offset = 18000, daylight = 0, Eastern Standard Time,
Eastern Standard Time
time UTC = 11:23:45, time local = 06:23:45
Thanks, Mellowman
DWORD tzResult;
TIME_ZONE_INFORMATION tzInfo;
// Get time zone offset
tzResult = GetTimeZoneInformation(&tzInfo);
m_Bias = (int)tzInfo.Bias;
switch(tzResult)
{
case TIME_ZONE_ID_STANDARD:
m_Bias += (int)tzInfo.StandardBias;
m_TZ = tzInfo.StandardName;
break;
case TIME_ZONE_ID_DAYLIGHT:
m_Bias += (int)tzInfo.DaylightBias;
m_TZ = tzInfo.DaylightName;
break;
case TIME_ZONE_ID_UNKNOWN:
break;
default:
m_Bias = 0;
}
m_Bias now holds the correct timezone offset from UTC in seconds for the
local time regardless of the time of year (assuming the computer has a
correctly configured clock and operating system). GetTimeZoneInformation()
is a Win32 function IIRC.
"Patric" <patr...@hotmail.com> wrote in message
news:01b301c393fe$5aef3bf0$a101...@phx.gbl...