【c++数据处理】---标准时间转UTC时间戳

标准时间转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();
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值