开发者

SystemTimeToTzSpecificLocalTime - how to get utc offset and time zone

开发者 https://www.devze.com 2022-12-15 18:32 出处:网络
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, SystemTimeToTzSpecificLo

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, &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;
}

`

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号