I have a two datetime in string format. for example
string str1 = "20160302101710"; //YYYYMMDDHHMMSS
string str2 = "20160302101715"; //same as above
Now, i need difference between two datetime is greater that 24Hours.
I have tried my problem as follows
I parsed the both string and put as follows:
#include <iostream>
using namespace std;
int main() {
time_t rawtime, rawtime1;
struct tm * timeinfo, *timeinfo1;
timeinfo->tm_year = 2016 ;
timeinfo->tm_mon = 03;
timeinfo->tm_mday = 02;
timeinfo->tm_hour = 10;
timeinfo->tm_min = 17;
timeinfo->tm_sec = 10;
rawtime = mktime(timeinfo);
timeinfo1->tm_year = 2016 ;
timeinfo1->tm_mon = 03;
timeinfo1->tm_mday = 02;
timeinfo1->tm_hour = 10;
timeinfo1->tm_min = 17;
timeinfo1->tm_sec = 15;
rawtime1 = mktime(timeinfo1);
cout<<"Diff: "<< difftime(rawtime1,rawtime);
return 0;
}
But After execution output is nothing. Can anyone help me how to get the correct answer. Once I will get the diff in second. then i will convert into hours.
Thanks,
Aucun commentaire:
Enregistrer un commentaire