Skip to content

Instantly share code, notes, and snippets.

@kjk
Created July 21, 2020 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kjk/2cdc964488d0f63ba6b4d6ee1ed1397f to your computer and use it in GitHub Desktop.
Save kjk/2cdc964488d0f63ba6b4d6ee1ed1397f to your computer and use it in GitHub Desktop.
#include <chrono>
#include <iostream>
int main()
{
using namespace std::literals::chrono_literals;
std::chrono::nanoseconds t1 = 600ns;
std::chrono::microseconds t2 = 42us;
std::chrono::milliseconds t3 = 51ms;
std::chrono::seconds t4 = 61s;
std::chrono::minutes t5 = 88min;
auto t6 = 2 * 0.5h;
auto total = t1 + t2 + t3 + t4 + t5 + t6;
std::cout.precision(13);
std::cout << total.count() << " nanoseconds" << std::endl; // 8941051042600 nanoseconds
std::cout << std::chrono::duration_cast<std::chrono::hours>(total).count()
<< " hours" << std::endl; // 2 hours
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment