// tm struct example

#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;

int main()
{
    // get current date/time
    time_t now = time(0);
    struct tm* timeInfo = localtime(&now);

    cout << setfill('0');

    cout << "The current time is " << timeInfo->tm_mon + 1 << '/' << setw(2)
            << timeInfo->tm_mday << '/' << timeInfo->tm_year % 100 << ' '
            << timeInfo->tm_hour % 12 << ':' << setw(2) << timeInfo->tm_min << ':'
            << setw(2) << timeInfo->tm_sec
            << (timeInfo->tm_hour >= 12 ? " PM" : " AM") << endl;

    // When is the final
    struct tm theFinal;
    theFinal.tm_mon = 11; // December
    theFinal.tm_mday = 8;
    theFinal.tm_year = 120; //2020
    theFinal.tm_hour = 13;
    theFinal.tm_min = 45;
    theFinal.tm_sec = 0;
    theFinal.tm_isdst = 0; // is daylight savings time

    time_t finalTime = mktime(&theFinal);

    cout << "The final is " << ctime(&finalTime) << endl;

    int secondsToFinal = static_cast<int>(difftime(finalTime, now));

    const int SecsPerDay = 24 * 60 * 60;
    const int SecsPerHour = 60 * 60;
    const int SecsPerMin = 60;

    // calculate the time until the final
    int days, hours, minutes, seconds;
    days = secondsToFinal / SecsPerDay;
    hours = (secondsToFinal - days * SecsPerDay) / SecsPerHour;
    minutes = (secondsToFinal - days * SecsPerDay - hours * SecsPerHour) / SecsPerMin;
    seconds = secondsToFinal - days * SecsPerDay - hours * SecsPerHour - minutes*SecsPerMin;

    cout << "Time until final = "  
         << days << " days " << hours << " hours " << minutes << " minutes " << seconds << " seconds" << endl;
}