fork(3) download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <ctime>
  4. #include <stdlib.h>
  5. #include <limits>
  6.  
  7. int main()
  8. {
  9. setenv("TZ", "/usr/share/zoneinfo/America/New_York", 1); // POSIX-specific
  10.  
  11. std::time_t t = std::time(nullptr);
  12. std::tm tm = *std::localtime(&t);
  13. std::cout << "Today is " << std::put_time(&tm, "%c %Z")
  14. << " and DST is " << (tm.tm_isdst ? "in effect" : "not in effect") << '\n';
  15. tm.tm_year = 550;
  16. tm.tm_year = std::numeric_limits< decltype( tm.tm_year ) >::max();
  17. tm.tm_mon = 88;
  18. tm.tm_mday = 200;
  19. //tm.tm_mon -= 100; // tm_mon is now outside its normal range
  20. auto err = std::mktime(&tm); // tm_dst is not set to -1; today's DST status is used
  21. std::cout << "100 months ago was " << std::put_time(&tm, "%c %Z")
  22. << " and DST was " << (tm.tm_isdst ? "in effect" : "not in effect") << '\n';
  23. std::cout << err << "\n";
  24. }
Success #stdin #stdout 0s 4256KB
stdin
Standard input is empty
stdout
Today is           Thu Apr 19 09:07:40 2018 EDT and DST is in effect
100 months ago was Thu ? 200 09:07:40 -2147481749 EDT and DST was in effect
-1