Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- using namespace std;
- void strPrintTime(char* des, time_t& t) {
- tm *pTime = gmtime(&t);
- strftime(des, 26, "%Y-%m-%d %H:%M:%S", pTime);
- }
- int main()
- {
- std::string startTime = "2017/10/19 01:22:00";
- time_t tStart;
- int yy, month, dd, hh, mm, ss;
- struct tm whenStart;
- const char *zStart = startTime.c_str();
- sscanf(zStart, "%d/%d/%d %d:%d:%d", &yy, &month, &dd, &hh, &mm, &ss);
- cout << yy << endl;
- cout << month << endl;
- cout << dd << endl;
- cout << hh << endl;
- cout << mm << endl;
- cout << ss << endl;
- whenStart.tm_year = yy - 1900;
- whenStart.tm_mon = month - 1;
- whenStart.tm_mday = dd;
- whenStart.tm_hour = hh;
- whenStart.tm_min = mm;
- whenStart.tm_sec = ss;
- whenStart.tm_isdst = -1;
- tStart = mktime(&whenStart);
- std::cout << tStart << std::endl;
- char des[100];
- strPrintTime(des, tStart);
- std::cout << des << std::endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement