Looking for the next “Daylight Saving Time” using the Windows registery
使用Windows注册表查找下一个"夏令时"。
我必须使用旧版本的Borland C ++。
夏令时的想法随绝对日期而变化
登记处的"欧洲标准时间"表示"夏令时"发生在3月的第5次发生,这是假的,因为它是第4次发生。 MSDN doc。
所以当我这样做时:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | 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(×tr); struct tm * temp = localtime(&standard); if(temp->tm_wday == systemTime.wDayOfWeek) { occ++; } if(occ >= sysemTime.wDay) { found = true; printf(" Found: %s", asctime( ×tr )); } } } int main(int argc, char* argv[]) { // Get the timezone info. TIME_ZONE_INFORMATION TimeZoneInfo; GetTimeZoneInformation( &TimeZoneInfo ); DYNAMIC_TIME_ZONE_INFORMATION TimeZoneInfoDyn; printf(" StandardDate %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(" DaylightDate %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; } |
它显示:
1 2 | Found: Sun Oct 29 03:00:00 2017 Found: Sun Apr 01 03:00:00 2018 |
代替 :
1 2 | Found: Sun Oct 29 03:00:00 2017 Found: Sun Mar 25 03:00:00 2018 |
我究竟做错了什么?
The"W. Europe Standard Time" in the registery says that the"Daylight Saving Time" occurs in the 5th occurance of the sunday of March which is false because it is the 4th occurance.
从链接答案中引用的文档:
(1 to 5, where 5 indicates the final occurrence during the month if that day of the week does not occur 5 times).
所以这不是假的。
此外,在循环中,在检查是否已达到所需日期之前,递增
顺便说一下,