使用 Windows 寄存器查找下一个"Daylight Saving Time"
Looking for the next "Daylight Saving Time" using the Windows registery
使用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(×tr);
struct tm * temp = localtime(&standard);
if(temp->tm_wday == systemTime.wDayOfWeek) {
occ++;
}
if(occ >= sysemTime.wDay) {
found = true;
printf("nnFound: %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("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_mday
和occ
。如果你一开始就这样做,你会过火的。
顺便说一下,sysemTime
拼写错误。
相关文章:
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 为什么我会收到"Run-Time Check Failure #2 - Stack around the variable 'pr' was corrupted"错误?
- 解析某些行的文本和输出"time of appearance"
- 返回time()库函数的数据类型
- 如何将 time-uuid(存储在 boost uuid 中)转换为时间戳/自纪元以来的时间?
- 如何从 boost::p osix_time::p time 获取秒数
- 调用 dll 函数时"Run-Time Check Failure #0 - The value of ESP"
- C++ SRAND(time(0)) 在猜谜游戏中不起作用
- 即使包含 <time.h 后仍"‘CLOCK_PER_SEC’ was not declared in this scope"错误>
- struct TM time;vs TM time = {}.输出相同但不相同?
- 使用 Windows 寄存器查找下一个"Daylight Saving Time"
- c++ get millsecond time
- "Feature X requires run-time support"的含义是什么?
- 如何传递以 "size determined at run time" 作为引用的动态分配数组?
- constexpr - "Evaluate value at compile time"到底是什么意思?
- "Time"库形式 Arduino 显示不正确的值
- 自定义 Python 构建 - time.so:未定义的符号:PyExc_ValueError
- C++名称查找来自 <time.h 的函数>
- 为什么即使我反复重置它,srand(time(NULL))也能顺利工作
- C STD :: Local Time Daylight节省时间规则(DST)欧洲与美国人