• Log in
Anwen  Share and Create
  • Book
  • Movies
  • Music
  • SF
  • Goodlink
  • Asks
  • Eyeopen
  • Create

C++ 中获取纳秒精度的时间

Sharer: 阅微堂 January 5, 2020 at 11:00 pm
Link Share :https://zhiqiang.org/coding/cpp-get-time-in-nanoseconds.html - via RSS

主要函数是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;
}
作者暂无likerid, 赞赏暂由本网站代持,当作者有likerid后会全部转账给作者(我们会尽力而为)。

Tips: Until now, everytime you want to store your article, we will help you store it in Filecoin network. In the future, you can store it in Filecoin network using your own filecoin.


Support author:
Author's Filecoin address:
Or you can use Likecoin to support author:
tags:编程 C++ 代码片段

0 0

2012-2018 Anwen All of our posts are default licensed under CC BY 4.0 About Help Changelog Telegram
Today Quote: 只要有了和平、低税收和宽容的司法当局,一个国家要达到最高富裕水平不需要其它东西。 -- 亚当·斯密