fork(4) download
  1. #include <time.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <iostream>
  5.  
  6. int main()
  7. {
  8. const char charTime[] = "1:1:1970:20:44:57";
  9. int hh, mm, ss, dd, mth, yy;
  10. sscanf( charTime, "%d:%d:%d:%d:%d:%d", &dd, &mth, & yy, &hh, &mm, &ss);
  11.  
  12. struct tm when ;
  13. memset( &when, 0, sizeof( struct tm ) ) ; // *****
  14. when.tm_mday = dd;
  15. when.tm_mon = mth - 1 ; // ***** Jan == 0, Dec == 11
  16. when.tm_year = yy - 1900 ; // ***** years since 1900
  17. when.tm_hour = hh;
  18. when.tm_min = mm;
  19. when.tm_sec = ss;
  20.  
  21. time_t converted = mktime(&when);
  22. std::cout << converted << '\n' ;
  23. }
  24.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
74697