在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)
看起来对不对?