#include <iostream>
#include <chrono>
#include <ctime>
#include <thread>
// Abbreviation: aliasing a long namespace name.
namespace ch = std::chrono;
int main() {
// Get current time
auto now = ch::system_clock::now();
// Convert to time_t for readable formatting
std::time_t now_c = ch::system_clock::to_time_t(now);
std::cout << "Clock ticked!\n";
// Print human-readable time
std::cout << "Current time: " << std::ctime(&now_c);
// Show epoch duration in seconds
auto since_epoch = now.time_since_epoch();
auto seconds = ch::duration_cast<ch::seconds>(since_epoch).count();
std::cout << "Seconds since epoch: " << seconds << "\n";
// Demonstrate a duration and sleep
ch::milliseconds pause(1500);
std::cout << "Sleeping for " << pause.count() << " ms...\n";
std::this_thread::sleep_for(pause);
// Show time again after sleep
auto later = ch::system_clock::now();
auto diff = later - now;
auto diff_ms = ch::duration_cast<ch::milliseconds>(diff).count();
std::cout << "Elapsed after sleep: " << diff_ms << " ms\n";
}
/*
run:
Clock ticked!
Current time: Thu Jul 9 15:02:28 2026
Seconds since epoch: 1783609348
Sleeping for 1500 ms...
Elapsed after sleep: 1501 ms
*/