I am trying to get the unix timestamp to milliseconds in a float when I call this function, which is probably 30 times / second. Timestamp returned by less always the same, when I type it up std::cerr, I get a different value. I create a variable every time I call a function, so I'm not sure what I'm doing wrong here. Any help would be appreciated.
float GetUnixTimestamps()
{
float milliseconds_since_epoch =
std::chrono::duration_cast<std::chrono::milliseconds>
(std::chrono::system_clock::now().time_since_epoch()).count();
std::cerr << milliseconds_since_epoch << std::endl;
return milliseconds_since_epoch;
}
EDIT: as per suggestion I am using C ++ 11 and should compile this on both Windows x64, x86, and Linux (mainly Ubuntu and CentOS). I would like to get the current time in unix. I already read the posts SO 19555121 and 16177295 , but the value still remains the same for the timestamp.
source
share