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 just get it as a uint?
How do I get a uint unix timestamp in C++? I’ve googled a bit
Share
C++20 introduced a guarantee that
time_since_epochis relative to the UNIX epoch, and cppreference.com gives an example that I’ve distilled to the relevant code, and changed to units of seconds rather than hours:Using C++17 or earlier,
time()is the simplest function – seconds since Epoch, which for Linux and UNIX at least would be the UNIX epoch. Linux manpage here.The cppreference page linked above gives this example: