fork download
  1. #include <iostream>
  2. #include <cstring>
  3. #include <ctime>
  4. #include <iomanip> // for std::put_time
  5. using namespace std;
  6.  
  7. time_t test (unsigned int date, unsigned int hhmmss)
  8. {
  9. int yyyy = (int) date / 10000;
  10. int mn = (int) date / 100 - (yyyy * 100);
  11. int dd = (int) date - (yyyy * 10000) - (mn * 100);
  12.  
  13. struct tm t;
  14. memset(&t, 0, sizeof(t));
  15.  
  16. t.tm_year = yyyy - 1900;
  17. t.tm_mon = mn - 1;
  18. t.tm_mday = dd;
  19. t.tm_hour = hhmmss / 10000;
  20. t.tm_min = hhmmss / 100 - (t.tm_hour * 100);
  21. t.tm_sec = hhmmss - (t.tm_hour * 10000) - (t.tm_min * 100);
  22. t.tm_isdst = -1;
  23. return mktime(&t);
  24. }
  25.  
  26. int main() {
  27. time_t ttt = test(20250528, 112299);
  28. std::tm* local_tm = std::localtime(&ttt); // convert to local time structure
  29.  
  30. std::cout << "Current time: "
  31. << std::put_time(local_tm, "%Y-%m-%d %H:%M:%S") << std::endl;
  32. cout << "ok." << endl;
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Current time: 2025-05-28 11:23:39
ok.