example3_system_clock_calendar_time.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <chrono>
#include <ctime>

int main() {
    auto now = std::chrono::system_clock::now();
    std::time_t now_c = std::chrono::system_clock::to_time_t(now);

    std::cout << "Current time: " << std::ctime(&now_c);

    auto one_day = std::chrono::hours(24);
    auto tomorrow = now + one_day;
    std::time_t tomorrow_c = std::chrono::system_clock::to_time_t(tomorrow);

    std::cout << "Tomorrow: " << std::ctime(&tomorrow_c);

    return 0;
}
Back to chrono