1

I have a timeval which is 0 seconds and 0 microseconds. I am therefore expecting zero hours:

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

However, h keeps outputting the value 1, which I presume is because localtime() is adding an extra hour for daylight savings.

How can I prevent this extra hour being added?

UPDATE

std::cout << "d: " << nowtm2->tm_isdst << std::endl;

outputs zero

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
user997112
  • 29,025
  • 43
  • 182
  • 361

0 Answers0