如何在C ++中以毫秒为单位获取时间
问题描述:
在 Java 中,您可以这样做:
In Java you can do this:
long now = (new Date()).getTime();
我怎样才能在 C++ 中做同样的事情?
How can I do the same but in C++?
答
标准 C++ 中没有这样的方法(标准 C++ 中只有秒精度,没有毫秒).您可以以非便携方式进行,但由于您没有指定,我将假设您需要一个便携解决方案.我想说,你最好的选择是 boost 函数 microsec_clock::local_time().
There is no such method in standard C++ (in standard C++, there is only second-accuracy, not millisecond). You can do it in non-portable ways, but since you didn't specify I will assume that you want a portable solution. Your best bet, I would say, is the boost function microsec_clock::local_time().