Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get future time value

Tags:

c++

#include <time.h>
#include <iostream>

using namespace std;

int main()
{
    time_t current = time(0);

    cout << ctime(&current) << endl; 
    return 0;
}

How can I get the future time, say 1 hour later, from the current time?

like image 620
FAS Avatar asked Mar 26 '26 07:03

FAS


1 Answers

time(2) returns the number of seconds since 1970-01-01 00:00:00 +0000 (UTC). One hour later would be current + 3600.

time_t current   = time(0);
time_t inOneHour = current + (60*60); // 60 minutes of 60 sec.

cout << "Now: " << ctime(&current) << "\n" 
     << "In 1 hour: " << ctime(&inOneHour)
     << "\n";
like image 99
Marcus Borkenhagen Avatar answered Mar 27 '26 19:03

Marcus Borkenhagen