我有一个 0 秒和 0 微秒的时间。因此,我期待零小时:
//Create a timeval representing 0 microseconds since 1970
struct timeval test;
test.tv_sec = 0;
test.tv_usec = 0;
struct tm *nowtm2;
time_t nowtime2;
nowtime2 = test.tv_sec;
nowtm2 = localtime(&nowtime2);
//This should output 0, but is outputting 1
std::cout << "h: " << nowtm2->tm_hour;
但是,h
一直输出值 1,我认为这是因为localtime()
为夏令时增加了一个额外的小时。
我怎样才能防止这个额外的小时被添加?
更新
std::cout << "d: " << nowtm2->tm_isdst << std::endl;
输出为零