Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3.  
  4. using namespace std;
  5. void strPrintTime(char* des, time_t& t) {
  6. tm *pTime = gmtime(&t);
  7. strftime(des, 26, "%Y-%m-%d %H:%M:%S", pTime);
  8. }
  9.  
  10. int main()
  11. {
  12. std::string startTime = "2017/10/19 01:22:00";
  13.  
  14. time_t tStart;
  15. int yy, month, dd, hh, mm, ss;
  16. struct tm whenStart;
  17. const char *zStart = startTime.c_str();
  18.  
  19. sscanf(zStart, "%d/%d/%d %d:%d:%d", &yy, &month, &dd, &hh, &mm, &ss);
  20. cout << yy << endl;
  21. cout << month << endl;
  22. cout << dd << endl;
  23. cout << hh << endl;
  24. cout << mm << endl;
  25. cout << ss << endl;
  26.  
  27. whenStart.tm_year = yy - 1900;
  28. whenStart.tm_mon = month - 1;
  29. whenStart.tm_mday = dd;
  30. whenStart.tm_hour = hh;
  31. whenStart.tm_min = mm;
  32. whenStart.tm_sec = ss;
  33. whenStart.tm_isdst = -1;
  34.  
  35. tStart = mktime(&whenStart);
  36.  
  37. std::cout << tStart << std::endl;
  38. char des[100];
  39. strPrintTime(des, tStart);
  40. std::cout << des << std::endl;
  41.  
  42. system("pause");
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement