在Java中,我们可以使用System.currentTimeMillis()以纪元时间为单位获取当前时间戳,以毫秒为单位 -
当前时间与UTC时间1970年1月1日午夜之间的差值,以毫秒为单位.
在C++中如何获得相同的东西?
目前我用它来获取当前时间戳 -
struct timeval tp;
gettimeofday(&tp, NULL);
long int ms = tp.tv_sec * 1000 + tp.tv_usec / 1000; //get current timestamp in milliseconds
cout << ms << endl;
Run Code Online (Sandbox Code Playgroud)
看起来对不对?
问题是,我必须以方便的格式以毫秒为单位获取当前时间.
期望输出的示例:
21小时04分12秒512毫秒
我知道如何在几秒钟内获得这种格式,但我不知道如何让我的手在几毫秒?