用合适的系统调用替换 linux 中的 ftime() 系统调用

Replace ftime() system call in linux with a suitable system call

替换 ftime() 系统调用已过时。我需要一个合适的系统调用来获取以毫秒为单位的时间。我能够找到 time()、gettimeofday()。但是这些不符合我的要求,因为我希望 return 时间精确到毫秒。 谁能给我推荐合适的系统调用。

怎么样:

auto timepoint std::chrono::system_clock::now();
auto since_epoch =  timepoint.time_since_epoch()
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(since_epoch) // epoch is implementation specific
std::cout << "Time in milliseconds: ";
std::cout << milliseconds.count() << '/n';

?

如果它必须是系统调用或者你不能使用 C++11(对于 std::chrono::high_resolution_clock),你可能会使用 clock_gettime(3).