fork download
  1. #include <iostream>
  2. #include <ctime>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. std::time_t t = std::time(NULL);
  8. std::tm time_1 = *std::localtime(&t);
  9. tm time_2 = time_1;
  10.  
  11. time_1.tm_hour = 10;
  12. time_1.tm_min = 4;
  13.  
  14. time_2.tm_hour = 11;
  15. time_2.tm_min = 5;
  16.  
  17. std::time_t t1 = mktime(&time_1);
  18. if ( t1 == -1 )
  19. {
  20. cout << "Problem in call to mktime, with time_1\n";
  21. return 1;
  22. }
  23.  
  24. std::time_t t2 = mktime(&time_2);
  25. if ( t2 == -1 )
  26. {
  27. cout << "Problem in call to mktime, with time_2\n";
  28. return 1;
  29. }
  30.  
  31. double diff = difftime (t2, t1);
  32.  
  33. cout << diff << endl;
  34.  
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
3660