1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#include <iostream>
#include <string>
#include <regex>
#include <fstream>
#include <sstream>
#include <time.h>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <iomanip>
using namespace std;
vector<string> explode(const string& str, const char& ch) {
string next;
vector<string> result;
for (string::const_iterator it = str.begin(); it != str.end(); it++) {
if (*it == ch) {
if (!next.empty()) {
result.push_back(next);
next.clear();
}
} else {
next += *it;
}
}
if (!next.empty())
result.push_back(next);
return result;
}
double DateToTimeStamp(string date){
string Millisecond = date.substr(date.rfind(","),date.size()-date.rfind(","));
std::vector<std::string> MyTime = explode(date.substr(0,date.rfind(",")), ':');
time_t now = time(NULL);
struct tm * tmdate = localtime(&now);
tmdate->tm_hour = atoi(MyTime[0].c_str());
tmdate->tm_min = atoi(MyTime[1].c_str());
tmdate->tm_sec = atoi(MyTime[2].c_str());
now = mktime(tmdate);
std::ostringstream strs;
strs << static_cast<double> (now) << Millisecond;
string test = strs.str();
return atof(test.c_str());
}
int main(int argc, char *argv[])
{
double Decal = 0;
for(int n=1; n<argc; n++){
string heure = argc[n];
if(Decal==0) Decal=DateToTimeStamp(heure);
cout << DateToTimeStamp(result[a])-Decal << endl;
}
} |
Partager