Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) std::mktime

 

std::mktime does some things [1], but the example below will not detect any changes:

 

#include <ctime>
#include <iostream>

std::ostream& operator<<(std::ostream& os, const std::tm& t)
{
  os
    << "sec: " << t.tm_sec << '\n'
    << "min: " << t.tm_min << '\n'
    << "hour: " << t.tm_hour << '\n'
    << "mday: " << t.tm_mday << '\n'
    << "mon: " << t.tm_mon << '\n'
    << "year: " << t.tm_year << '\n'
    << "wday: " << t.tm_wday << '\n'
    << "yday: " << t.tm_yday << '\n'
    << "isdst: " << t.tm_isdst << '\n';
  return os;
};

int main ()
{
  std::time_t rawtime;
  std::time(&rawtime);
  std::tm * const timeinfo = std::localtime(&rawtime);

  std::cout << (*timeinfo) << '\n';

  std::mktime(timeinfo);

  std::cout << (*timeinfo) << '\n';
}

 

Screen output:

 

sec: 15
min: 38
hour: 10
mday: 28
mon: 5
year: 111
wday: 2
yday: 178
isdst: 1

sec: 15
min: 38
hour: 10
mday: 28
mon: 5
year: 111
wday: 2
yday: 178
isdst: 1

 

 

 

 

 

External links

 

 

 

 

 

 

References

 

  1. cplusplus.com page about std::mktime

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict