Is there cross-platform solution to get seconds since epoch, for windows i use
long long NativesGetTimeInSeconds()
{
return time (NULL);
}
But how to get on Linux?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re already using it:
std::time(0)(don’t forget to#include <ctime>). However, whetherstd::timeactually returns the time since epoch isn’t specified in the standard (C11, referenced by the C++ standard):For C++, C++11 and later provide
time_since_epoch. However, before C++20 the epoch ofstd::chrono::system_clockwas unspecified and therefore possibly non-portable in previous standards.Still, on Linux the
std::chrono::system_clockwill usually use Unix Time even in C++11, C++14 and C++17, so you can use the following code: