Created
April 22, 2019 20:04
-
-
Save arrieta/a46578054f66ff060f2803062a4e80e7 to your computer and use it in GitHub Desktop.
UNIX Timestamp in C++ (Guaranteed in C++20; de facto standard pre-C++20)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// @file timestamp.hpp | |
/// @brief Return UNIX timestamp. | |
/// @author J. Arrieta <[email protected]> | |
/// @copyright (C) 2019 Nabla Zero Labs | |
/// @license MIT | |
#pragma once | |
#include <chrono> | |
#include <cstdint> | |
namespace nzl { | |
/// @brief Return total nanoseconds elapsed since Jan 01, 1970 00:00:00 UTC. | |
/// @note Guaranteed in C++20; de facto standard pre-C++20. | |
inline std::uint64_t unix_nanos() noexcept { | |
using namespace std::chrono; | |
const auto elapsed = system_clock::now().time_since_epoch(); | |
return duration_cast<nanoseconds>(elapsed).count(); | |
} | |
} // namespace nzl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment