views:

278

answers:

1

I have a need to convert a utc system time to local time and find the corresponding utc offset. I wouldn't mind getting the time zone also. As far as I can tell, SystemTimeToTzSpecificLocalTime returns no information on these.

Anyone have a good way of determining the UTC offset and time zone?

A: 

Here's one way of doing this.

`

long int    SBias, SSeconds, LSeconds;

SYSTEMTIME STime, LTime; SystemTimeToTzSpecificLocalTime (&TZ, &STime, &LTime);

SSeconds = 3600L * STime.wHour + 60L * STime.wMinute + STime.wSecond;
LSeconds = 3600L * LTime.wHour + 60L * LTime.wMinute + LTime.wSecond;

SBias = 60L * (TZ.Bias + TZ.StandardBias);

SSeconds -= SBias;
if (SSeconds < 0) SSeconds += 24L * 3600L;

if (SSeconds == LSeconds)
{
    tmX.tm_isdst = 0;
    StdTime      = true;
}
else
{
    tmX.tm_isdst = 1;
    StdTime      = false;
}

`

Mike D