SystemTimeToTzSpecificLocalTime - how to get utc offset and time zone
I have a need to convert a utc system time t开发者_JAVA百科o 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?
Here's one way of doing this.
`
long int SBias, SSeconds, LSeconds;
SYSTEMTIME STime, LTime; SystemTimeToTzSpecificLocalTime (&TZ, &STime, <ime);
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;
}
`
精彩评论