0

我需要将 utc 系统时间转换为本地时间并找到相应的 utc 偏移量。我也不介意获取时区。据我所知, SystemTimeToTzSpecificLocalTime 没有返回关于这些的信息。

有人有确定UTC偏移量和时区的好方法吗?

4

1 回答 1

1

这是执行此操作的一种方法。

`

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

`

于 2010-01-10T12:48:46.050 回答