#include <time.h>
#include <iostream>
using namespace std;
int main()
{
time_t current = time(0);
cout << ctime(¤t) << endl;
return 0;
}
如何从当前时间1小时后得到未来的时间?
答案 0 :(得分:5)
time(2)返回自1970-01-01 00:00:00 +0000(UTC)以来的秒数。一小时后将是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";