2018-10-01 00:06:16.700000000
我有一个时间序列的数据文件,其中包含上述时间戳。我需要将其转换为距离纪元开始的纳秒数,然后需要对时间戳进行毫秒、微秒或纳秒的加法(偏移)。最后,对于某些记录,需要将其重新格式化为上述格式。
我在时间点创建方面遇到了问题 - 如何表示纳秒...使用微秒时可以正常工作。
请帮忙修复下面的代码片段...并且一旦我获得了距离纪元开始的纳秒数,如何回到上述的时间戳格式。
std::string ts("23 01 2020 20:59:59.123456789");
XXXX (ts);
void XXXXX (string timestamp)
{
stringstream temp_ss(timestamp);
tm temp_time_object = {};
temp_ss >> get_time (&temp_time_object, "%Y/%m/%d %H:%M:%S");
chrono::system_clock::time_point temp_time_point = system_clock::from_time_t(mktime(&temp_time_object));
// chrono::high_resolution_clock::time_point temp_time_point1 = temp_time_point;
auto nsecs = stol (timestamp.substr (timestamp.find_first_of('.')+1,9));
// +++ This is where I GET stuck forming the time_point....
// I've tried this so many different ways ....
// Is it that the system_clock cannot accept nanos?
temp_time_point += nanoseconds (nsecs);
auto micro_from_epoch = duration_cast<nanoseconds> (temp_time_point.time_since_epoch()).count();
cout << micro_from_epoch << endl;
}