使用 Windows 寄存器查找下一个"Daylight Saving Time"

Looking for the next "Daylight Saving Time" using the Windows registery

本文关键字:Daylight Time Saving 下一个 Windows 寄存器 查找 使用      更新时间:2023-10-16

使用Windows注册表查找下一个"夏令时"。

我必须使用旧版本的Borland C++。

夏令时的想法与绝对日期更改

注册表中的"W. Europe 标准时间"说"夏令时"发生在 3 月星期日的第 5 次出现,这是错误的,因为它是第 4 次出现。MSDN 文档。

所以当我在做:

void findDate(int year, SYSTEMTIME systemTime)
{
struct tm timestr;
int occ = 0;
bool found = false;
timestr.tm_year = year - 1900;
timestr.tm_mon = systemTime.wMonth - 1;
timestr.tm_mday = 0;
timestr.tm_hour = systemTime.wHour;
timestr.tm_min = systemTime.wMinute;
timestr.tm_sec = systemTime.wSecond;
timestr.tm_isdst = 0;
while((timestr.tm_mday <= 31 && !found)) {
timestr.tm_mday += 1;
time_t standard = mktime(&timestr);
struct tm * temp = localtime(&standard);
if(temp->tm_wday == systemTime.wDayOfWeek) {
occ++;
}
if(occ >= sysemTime.wDay) {
found = true;
printf("nnFound: %s", asctime( &timestr ));
}
}
}
int main(int argc, char* argv[])
{
// Get the timezone info.
TIME_ZONE_INFORMATION TimeZoneInfo;
GetTimeZoneInformation( &TimeZoneInfo );
DYNAMIC_TIME_ZONE_INFORMATION TimeZoneInfoDyn;
printf("nnStandardDate %d wDay%d wDayOfWeek%d %d %d %d", TimeZoneInfo.StandardDate.wMonth, TimeZoneInfo.StandardDate.wDay, TimeZoneInfo.StandardDate.wDayOfWeek, TimeZoneInfo.StandardDate.wHour, TimeZoneInfo.StandardDate.wMinute, TimeZoneInfo.StandardDate.wSecond);
printf("nDaylightDate %d wDay%d wDayOfWeek%d %d %d %d", TimeZoneInfo.DaylightDate.wMonth, TimeZoneInfo.DaylightDate.wDay, TimeZoneInfo.DaylightDate.wDayOfWeek, TimeZoneInfo.DaylightDate.wHour, TimeZoneInfo.DaylightDate.wMinute, TimeZoneInfo.DaylightDate.wSecond);
findDate(2017, TimeZoneInfo.StandardDate);
findDate(2018, TimeZoneInfo.DaylightDate);
getchar();
return 0;
}

它显示:

Found: Sun Oct 29 03:00:00 2017
Found: Sun Apr 01 03:00:00 2018

而不是:

Found: Sun Oct 29 03:00:00 2017
Found: Sun Mar 25 03:00:00 2018

我做错了什么?

登记册中的"W. Europe 标准时间"说"夏令时"发生在 3 月星期日的第 5 次出现,这是错误的,因为它是第 4 次出现。

从链接答案中引用的文档:

(1 到 5,其中 5 表示如果一周中的某一天未出现 5 次,则表示该月中的最后一次出现(。

所以这不是假的。

此外,在您的循环中,您会在检查您是否已经到达所需的日期之前递tm_mdayocc。如果你一开始就这样做,你会过火的。

顺便说一下,sysemTime拼写错误。