3
C++ 中获取纳秒精度的时间
source link: https://zhiqiang.org/coding/cpp-get-time-in-nanoseconds.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
C++ 中获取纳秒精度的时间
主要函数是timespec_get
,可参考https://zh.cppreference.com/w/c/chrono/timespec_get。
#include <time.h> std::string time_in_nanoseconds() { struct timespec ts; timespec_get(&ts, TIME_UTC); static char buff[64]; int end = strftime(buff, sizeof buff, "%Y-%m-%d %H:%M:%S", gmtime(&ts.tv_sec)); sprintf(buff + end, " %09ld", ts.tv_nsec); return buff; }
Q. E. D.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK