标准时间转UTC时间戳
#include "pch.h"
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include<fstream>
#include<iostream>
#include<string>
#include <vector>
#include<sstream>
#include<algorithm>
#include<math.h>
#include "pch.h"
#include <iomanip>
#include <time.h>
#include <comutil.h>
using namespace std;
vector<string> splitString(string srt, char symbol)
{
istringstream istr(srt);
vector<string> params;
string param;
while (getline(istr, param, symbol))
{
params.push_back(param);
}
return params;
}
//标准时间格式例如:2016:08:02 12:12:30
int standard_to_stamp(char *str_time)
{
struct tm stm;
int iY, iM, iD, iH, iMin, iS;
memset(&stm, 0, sizeof(stm));
iY = atoi(str_time);
iM = atoi(str_time + 5);
iD = atoi(str_time + 8);
iH = atoi(str_time + 11);
iMin = atoi(str_time + 14);
iS = atoi(str_time + 17);
stm.tm_year = iY - 1900;
stm.tm_mon = iM - 1;
stm.tm_mday = iD;
stm.tm_hour = iH;
stm.tm_min = iMin;
stm.tm_sec = iS;
return (int)mktime(&stm);
}
void readFile()
{
ofstream ofile;
ofile.open("F://huyu//轨迹数据//all_Output.csv", ios::out | ios::trunc); //输出文件路径
string filePath = "F://huyu//轨迹数据//all.csv"; //输入文件路径
ifstream infile;
infile.open(filePath, ios::in);
if (!infile.is_open())
{
cout << "open File Failed." << endl;
}
string line;
int l = 0;
int n_id = 0;
string strCarId = "";
ofile << "id" << "," << "openid" << "," << "lat" << "," << "lng" << "," << "time" << endl;
int nl = 0;
while (getline(infile, line))
{
if (nl == 0) {
nl = 1;
}
else
{
cout << "正在处理第--------" << l++ << "--------行轨迹数据" << endl;
vector<string> params;
params = splitString(line, ',');
string stime = params[4];
stime.c_str();
int utc = standard_to_stamp((char*)stime.c_str());
ofile << setprecision(18) << params[0] << "," << params[1] << "," << params[2] << "," << params[3] << "," << utc << endl;//
}
}
infile.close();
ofile.close();
cout << "轨迹数据预处理完成!" << endl;
}
int main()
{
readFile();
}