Skip to content

Instantly share code, notes, and snippets.

@kjk
Created Jul 21, 2020
Embed
What would you like to do?
#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