I am trying to get unix timestamp upto milliseconds in float whenever I call this function which is probably 30 times/second. The timestamp that the function below returns is always the same however, when I print it to std::cerr
I get different value. I am creating the variable every time I call the function so I am not sure what I am doing wrong here. Any help will 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 the suggestion I am using C++ 11 and need to compile this on both Windows x64, x86 and Linux (mainly Ubuntu and CentOS). I would like to get the current time in unix. I have already read the S.O posts 19555121 and 16177295 but the value still remains the same for the timestamps.