How do I get a uint
unix timestamp in C++? I\'ve googled a bit and it seems that most methods are looking for more convoluted ways to represent time. Can\'t I j
As this is the first result on google and there's no C++20 answer yet, here's how to use std::chrono to do this:
#include
//...
using namespace std::chrono;
int64_t timestamp = duration_cast(system_clock::now().time_since_epoch()).count();
In versions of C++ before 20, system_clock's epoch being Unix epoch is a de-facto convention, but it's not standardized. If you're not on C++20, use at your own risk.