0

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?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Mike D
  • 2,753
  • 8
  • 44
  • 77

1 Answers1

1

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
  • 2,753
  • 8
  • 44
  • 77