C++: How do you a print a date a specific amount of time away from the current time?

85 Views Asked by At

I am experimenting with ctime but I can't, for the life of me, figure out how to print a date X days away from the current date. This is my program thus far:

#include "header.h"

int main()
{
    time_t current;
    struct tm * timedata;

    time(&current);
    timedata = localtime(&current);

    cout << "The current date and time is: " << asctime(timedata) << endl << endl;

    return 0;
}

If I'm correct, time(&current) returns the amount of seconds from January 1st, 2000, but the number I get seems too small for that to be it.. All help appreciated.

1

There are 1 best solutions below

2
On BEST ANSWER

time(&current) returns the number of seconds since Jan 1, 1970, UTC -0000.

Add n*86400, to get the time n days from/before the current time.

That assumes, of course, you won't cross the summer/winter time adjustment, if you happen to live in the part of the world that suffers from this bizarre concept...