如何在C ++中以毫秒为单位获取时间 [英] How to get the time in milliseconds in C++
本文介绍了如何在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().
这篇关于如何在C ++中以毫秒为单位获取时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文