Created
May 2, 2020 04:25
-
-
Save yasukei/7825d0d983682bc050caee2acdf3ea5c to your computer and use it in GitHub Desktop.
std::chrono
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
#include <iostream> | |
#include <iomanip> | |
#include <ctime> | |
#include <chrono> | |
int main() | |
{ | |
std::time_t t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); | |
std::cout << "UTC: " << std::put_time(std::gmtime(&t), "%F %T") << '\n'; | |
std::cout << "Local: " << std::put_time(std::localtime(&t), "%F %T %z") << '\n'; | |
std::chrono::steady_clock::time_point before = std::chrono::steady_clock::now(); | |
std::chrono::steady_clock::time_point after = std::chrono::steady_clock::now(); | |
std::chrono::duration<double, std::nano> elapsedNanoSec = after - before; | |
std::cout << "elapsed time: " << elapsedNanoSec.count() << "[ns]\n"; | |
return 0; | |
} |
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
UTC: 2020-05-02 04:24:49 | |
Local: 2020-05-02 13:24:49 +0900 | |
elapsed time: 300[ns] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment