#include <time.h>
#include <iostream>
using namespace std;
int main()
{
time_开发者_Python百科t current = time(0);
cout << ctime(¤t) << endl;
return 0;
}
How can I get the future time, say 1 hour later, from the current time?
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(¤t) << "\n"
<< "In 1 hour: " << ctime(&inOneHour)
<< "\n";
精彩评论