linux ptp同步 及 时间戳格式化输出
作者:互联网
ptp同步:https://blog.csdn.net/u013431916/article/details/83054369
用ptpd。对应的网口打开时钟协议即可。
时间戳格式化输出:
// 秒 毫秒 微秒 纳秒 std::cout << "i++ status :timestamp count" << scans[i].headers.at(102).timestamp.count() << std::endl;// 纳秒 int nacro = scans[i].headers.at(102).timestamp.count() % 1000000000; //纳秒 int micro = (scans[i].headers.at(102).timestamp.count() / 1000000) % 1000; //毫秒 time_t timeT = scans[i].headers.at(102).timestamp.count() / 1000000000; // 秒 struct tm* pTm; pTm = localtime(&timeT); char strTime[100]; sprintf(strTime, "%d-%02d-%02d %02d:%02d:%02d.%09d", 1900 + pTm->tm_year, 1 + pTm->tm_mon, pTm->tm_mday, pTm->tm_hour, pTm->tm_min, pTm->tm_sec, nacro); std::cout << "i++ status :timestamp 格式化:" << strTime << std::endl; char strTime2[100]; sprintf(strTime2, "%d-%02d-%02d %02d:%02d:%02d.%09d", pTm->tm_year, pTm->tm_mon, pTm->tm_mday, pTm->tm_hour, pTm->tm_min, pTm->tm_sec, nacro); std::cout << "i++ status :timestamp 格式化:" << strTime2 << std::endl;
标签:std,pTm,格式化,cout,year,tm,sec,linux,ptp 来源: https://www.cnblogs.com/gaara-zhang/p/16066528.html