#include // for cout #include // for time(), localtime(), and strftime() using namespace std; int main() { // Get the current time as seconds since the start of 1970. // These are “epoch seconds”. Store those in a variable of type // time_t, which is an alias for int, long int, or something similar. time_t now = time(nullptr); // Break the epoch seconds down into numeric // year/month/day/hour/minute/second. The function localtime() // returns a pointer to a struct tm, containing those values, but // struct tm * is too much work to type, so declare timevals as // “auto”, which means “compiler, you figure out the type”. auto timevals = localtime(&now); // Transform the broken-down time values into a human-readable // representation of the time. It will go into the C string buf. char buf[32]; strftime(buf, sizeof(buf), "%A, %B %d %T", timevals); // Write it for the user. cout << "The current time & date: " << buf << '\n'; // This program succeeded--indicate that with a zero. return 0; }