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;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章