对于我使用的 Windows,是否有跨平台解决方案可以获得自纪元以来的秒数
long long NativesGetTimeInSeconds()
{
return time (NULL);
}
但是如何上 Linux 呢?
原文由 Boris 发布,翻译遵循 CC BY-SA 4.0 许可协议
7 回答5.3k 阅读
3 回答2k 阅读✓ 已解决
4 回答4k 阅读
2 回答3.9k 阅读✓ 已解决
2 回答5.9k 阅读✓ 已解决
2 回答3.2k 阅读✓ 已解决
1 回答3.2k 阅读✓ 已解决
您已经在使用它:
std::time(0)
(不要忘记#include <ctime>
)。但是,std::time
实际上是否返回标准中未指定纪元以来的时间( C11 ,由 C++ 标准引用):// make the decltype slightly easier to the eye using seconds_t = std::chrono::seconds;
// return the same type as seconds.count() below does. // note: C++14 makes this a lot easier. decltype(seconds_t().count()) get_seconds_since_epoch() { // get the current time const auto now = std::chrono::system_clock::now();
}
”`