How to convert std::chrono::monotonic_clock::now() to milliseconds and cast it to long?
using steady_clock or high_resolution_clock from chrono is also same. I have seen into std::chrono::duration_cast<std::chrono::milliseconds> but I only want the current timestamp and not any duration gaps.
The current timestamp is defined with respect to some point in time (hence it is a duration). For instance, it is “typical” to get a timestamp with respect to the beginning of the Epoch (January 1st 1970, in Unix). You can do that by using
time_since_epoch():To get the value in milliseconds you would need to cast it to
std::chrono::milliseconds, instead.