Skip to content

Instantly share code, notes, and snippets.

@yasukei
Created May 2, 2020 04:25
Show Gist options
  • Save yasukei/7825d0d983682bc050caee2acdf3ea5c to your computer and use it in GitHub Desktop.
Save yasukei/7825d0d983682bc050caee2acdf3ea5c to your computer and use it in GitHub Desktop.
std::chrono
#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;
}
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